Skip to content

Commit dd41204

Browse files
committed
add: valid-palindrome solution
1 parent ac174f5 commit dd41204

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

valid-palindrome/JEONGBEOMKO.java

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class Solution {
2+
3+
/*
4+
time complexity: O(n)
5+
space complexity: O(n)
6+
*/
7+
8+
public boolean isPalindrome(String s) {
9+
10+
int left = 0;
11+
int right = s.length() - 1;
12+
13+
while (left < right) {
14+
while (left < right && !Character.isLetterOrDigit(s.charAt(left))) {
15+
left++;
16+
}
17+
18+
while (left < right && !Character.isLetterOrDigit(s.charAt(right))) {
19+
right--;
20+
}
21+
22+
if (Character.toLowerCase(s.charAt(left)) != Character.toLowerCase(s.charAt(right))) {
23+
return false;
24+
}
25+
26+
left++;
27+
right--;
28+
29+
}
30+
return true;
31+
}
32+
}

0 commit comments

Comments
 (0)