Skip to content

Commit 6a63316

Browse files
committed
valid-palindrome
1 parent 4846bd7 commit 6a63316

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

valid-palindrome/taekwon-dev.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 시간 복잡도: O(n)
3+
* - 정규식을 통해 Alphanumeric 만 남기기. -> O(n)
4+
* - 소문자로 변환 -> O(n)
5+
* - 투 포인터를 이용하기 때문에 -> O(n/2)
6+
* 공간 복잡도: O(n)
7+
*/
8+
class Solution {
9+
public boolean isPalindrome(String s) {
10+
s = s.replaceAll("[^a-zA-Z0-9]", "").toLowerCase();
11+
12+
char[] c = s.toCharArray();
13+
14+
int left = 0;
15+
int right = c.length - 1;
16+
17+
while (left < right) {
18+
if (c[left++] != c[right--]) {
19+
return false;
20+
}
21+
}
22+
return true;
23+
}
24+
}

0 commit comments

Comments
 (0)