String
in Coding Interview on String
문자열을 이용한 코드 팁
문자열에서 문자열 찾기
if (word.indexOf(prefix) != 0)
문자비교는 맵 또는 문자배열을 사용해서 체크
int[] alphabet = new int[26];
for (int i = 0; i < s.length(); i++) alphabet[s.charAt(i) - 'a']++;
문자열에서 숫자 정보 추출하기
digits.charAt(index) - '0'
문자열을 숫자로 컨버젼
int num = 0;
for (char c: s.toCharArray()) {
num = 10 * num + (c - '0');
}
문자열 스왑
public void swap(char[] s, int left, int right) {
char temp = s[left];
s[left] = s[right];
s[right] = temp;
}
문자열 리버스
public void reverse(char[] s, int start, int end) {
while (start < end) {
char temp = s[start];
s[start] = s[end];
s[end] = temp;
start++;
end--;
}
}
An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
Questions
[Easy]
- 14. Longest Common Prefix
- 28. Find the Index of the First Occurrence in a String
- 58. Length of Last Word
- 67. Add Binary
- 171. Excel Sheet Column Number
- 344. Reverse String
- 345. Reverse Vowels of a String
- 383. Ransom Note
- 387. First Unique Character in a String
- 409. Longest Palindrome
- 1047. Remove All Adjacent Duplicates In String
- 1071. Greatest Common Divisor of Strings
- 1165. Single-Row Keyboard
- 1427. Perform String Shifts
- 1668. Maximum Repeating Substring
- 1768. Merge Strings Alternately
- 1812. Determine Color of a Chessboard Square
- 2278. Percentage of Letter in String
- 2716. Minimize String Length
[Medium]
- 8. String to Integer (atoi)
- 49. Group Anagrams
- 71. Simplify Path
- 97. Interleaving String
- 139. Word Break
- 161. One Edit Distance
- 186. Reverse Words in a String II
- 271. Encode and Decode Strings
- 394. Decode String
- 402. Remove K Digits
- 443. String Compression
- 451. Sort Characters By Frequency
- 1209. Remove All Adjacent Duplicates in String II
- 1236. Web Crawler
- 2390. Removing Stars From a String
[Hard]
Subsequence
A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters. For example, “ace” is a subsequence of “abcde”.
- 187. Repeated DNA Sequences
- 392. Is Subsequence
- 516. Longest Palindromic Subsequence
- 1143. Longest Common Subsequence
- 2486. Append Characters to String to Make Subsequence
Substring
- 3. Longest Substring Without Repeating Characters
- 5. Longest Palindromic Substring
- 76. Minimum Window Substring
- 159. Longest Substring with At Most Two Distinct Characters
- 340. Longest Substring with At Most K Distinct Characters
- 1456. Maximum Number of Vowels in a Substring of Given Length
- 2405. Optimal Partition of String