Skip to content

Commit 0f36d9d

Browse files
committed
Time: 7 ms (52.41%), Space: 43.3 MB (69.11%) - LeetHub
1 parent afce0fb commit 0f36d9d

File tree

1 file changed

+32
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)