Leetcode 344번 문제는 단순히 주어진 문자열을 뒤집는 문제이다. 단 Space complexity (공간 복잡도) 가 O(1) 이
되도록 해야 한다.
class Solution {
public void reverseString(char[] s) {
int i = 0, j = s.length - 1;
while(j > i){
char temp = s[j];
s[j--] = s[i];
s[i++] = temp;
}
}
}
'LeetCode > String' 카테고리의 다른 글
[Easy] 20. Valid Parentheses (0) | 2022.11.14 |
---|---|
[Medium] 49. Group Anagrams (Amazon) (1) | 2022.09.20 |
[Medium] 1663. Smallest String With A Given Numeric Value (Microsoft) (0) | 2022.09.20 |
[Medium] 856. Score of Parentheses (0) | 2022.09.12 |
[Medium] 5. Longest Palindromic Substring (구글 코딩 테스트 기출 문제) (0) | 2022.09.11 |