string
-
[LeetCode] Valid Palindrome알고리즘 2019. 12. 5. 17:00
문제 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: For the purpose of this problem, we define empty string as valid palindrome. Example 1: Input: "A man, a plan, a canal: Panama" Output: true Example 2: Input: "race a car" Output: false Apporach isdigit(), isalpha()로 알파벳이나 숫자가 아닌것은 다 거르면서 앞글자 뒷글자를 맞춰보면 된다 isdigit(), isalpha() 두개..
-
[LeetCode] Decode Ways알고리즘 2019. 11. 25. 18:26
문제 A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given a non-empty string containing only digits, determine the total number of ways to decode it. Example 1: Input: "12" Output: 2 Explanation: It could be decoded as "AB" (1 2) or "L" (12). Example 2: Input: "226" Output: 3 Explanation: It could be decoded as "BZ" (2 ..
-
[LeetCode] Minimum Window Substring알고리즘 2019. 11. 5. 22:18
문제 Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). Example: Input: S = "ADOBECODEBANC", T = "ABC" Output: "BANC" Note: If there is no such window in S that covers all characters in T, return the empty string "". If there is such window, you are guaranteed that there will always be only one unique minimum window in S. Ap..
-
[LeetCode] Group Anagrams알고리즘 2019. 10. 29. 16:37
문제 Given an array of strings, group anagrams together. Example: Input: ["eat", "tea", "tan", "ate", "nat", "bat"], Output: [ ["ate","eat","tea"], ["nat","tan"], ["bat"] ] Note: All inputs will be in lowercase. The order of your output does not matter. Approach 각 string을 sort해보고 그 결과가 같으면 같은 그룹으로 묶는다. 이를 위해 map (혹은 unorderd_map)을 사용하였다. 시간복잡도는 총 string의 개수가 N개, string 하나의 최대 길이가 K일때 O(NKlogK)이다 O..
-
[LeetCode] Wildcard Matching알고리즘 2019. 10. 24. 22:39
문제 Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character. '*' Matches any sequence of characters (including the empty sequence). The matching should cover the entire input string (not partial). Note: s could be empty and contains only lowercase letters a-z. p could be empty and contains only lowercase letter..
-
[LeetCode] Count and Say알고리즘 2019. 10. 22. 16:48
문제 The count-and-say sequence is the sequence of integers with the first five terms as following:1. 1 2. 11 3. 21 4. 1211 5. 111221 1 is read off as "one 1" or 11. 11 is read off as "two 1s" or 21. 21 is read off as "one 2, then one 1" or 1211. Given an integer n where 1 ≤ n ≤ 30, generate the nth term of the count-and-say sequence. Note: Each term of the sequence of integers will be represented..