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]

[Medium]

[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”.

Substring

Valid

Anagram

Parentheses






© 2017. by yeopoong.github.io

Powered by yeopoong