Skip to content

Commit 393d096

Browse files
125. Valid Palindrome (java)
1 parent a68d3d6 commit 393d096

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Solution {
2+
public boolean isPalindrome(String s) {
3+
if (s == null || s.length() == 0) return true;
4+
int start = 0 , end = s.length() - 1;
5+
while (start < end) {
6+
char c = ' ';
7+
while (start < end) {
8+
c = s.charAt(start);
9+
if (c >= 'a' && c <= 'z' || c >= '0' && c <= '9') break;
10+
if (c >= 'A' && c <= 'Z') {
11+
c = (char) (c - 'A' + 'a');
12+
break;
13+
}
14+
start++;
15+
}
16+
char b = ' ';
17+
while (start < end) {
18+
b = s.charAt(end);
19+
if (b >= 'a' && b <= 'z' || b >= '0' && b <= '9') break;
20+
if (b >= 'A' && b <= 'Z') {
21+
b = (char) (b - 'A' + 'a');
22+
break;
23+
}
24+
end--;
25+
}
26+
if (start < end) {
27+
if (c != b) return false;
28+
start++;
29+
end--;
30+
}
31+
}
32+
return true;
33+
}
34+
}

0 commit comments

Comments
 (0)