Skip to content

Commit 950bb43

Browse files
committed
valid palindrome
1 parent b6acb32 commit 950bb43

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

valid-palindrome/se6816.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
투포인터 방식을 통해 맨 앞과 맨 끝 포인터에서 맨 끝 포인터가 맨 앞 포인터를 앞지를 때까지 비교하는 방식
3+
문자열 s의 길이 -> N
4+
시간 복잡도 : O(N)
5+
공간 복잡도 : O(1)
6+
*/
7+
class Solution {
8+
public boolean isPalindrome(String s) {
9+
s=s.toUpperCase();
10+
int start=0;
11+
int end=s.length()-1;
12+
while(start < end){
13+
char ch=s.charAt(start);
14+
char ch2=s.charAt(end);
15+
16+
// 문자 체크
17+
if(!((ch>=65 && ch<=90) || (ch>=48 && ch<=57))){
18+
start++;
19+
continue;
20+
}
21+
if(!((ch2>=65 && ch2<=90) || (ch2>=48 && ch2<=57))){
22+
end--;
23+
continue;
24+
}
25+
26+
if(ch==ch2){
27+
start++;
28+
end--;
29+
continue;
30+
}
31+
32+
return false;
33+
34+
}
35+
return true;
36+
}
37+
}

0 commit comments

Comments
 (0)