-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution125.java
More file actions
executable file
·29 lines (28 loc) · 914 Bytes
/
Copy pathSolution125.java
File metadata and controls
executable file
·29 lines (28 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution125 {
public boolean isPalindrome(String s) {
int left = 0, right = s.length() - 1;
while (left < right) {
char cleft = s.charAt(left), cright = s.charAt(right);
if (!Character.isDigit(cleft) && !ischar(cleft)) {
left++;
continue;
}
if (!Character.isDigit(cright) && !ischar(cright)) {
right--;
continue;
}
if (ischar(cleft)) cleft = Character.toLowerCase(cleft);
if (ischar(cright)) cright = Character.toLowerCase(cright);
if (cleft != cright) return false;
left++;
right--;
}
return true;
}
public boolean ischar(char c) {
boolean res = false;
res = res || (c >= 'a' && c <= 'z');
res = res || (c >= 'A' && c <= 'Z');
return res;
}
}