Skip to content

Commit 391efe4

Browse files
authored
Merge pull request #1313 from JEONGBEOMKO/main
[JEONGBEOMKO] Week 03 Solutions
2 parents b2b9712 + dd41204 commit 391efe4

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

valid-palindrome/JEONGBEOMKO.java

Lines changed: 32 additions & 0 deletions
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)