-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
24 lines (21 loc) · 750 Bytes
/
Solution.java
File metadata and controls
24 lines (21 loc) · 750 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
class Solution {
public boolean isPalindrome(String s) {
int i = 0,
j = s.length() - 1;
while (i < j) {
char start = s.charAt(i),
end = s.charAt(j);
if (!(('a' <= start && start <= 'z') || ('A' <= start && start <= 'Z') || ('0' <= start && start <= '9'))) {
i++;
} else if (!(('a' <= end && end <= 'z') || ('A' <= end && end <= 'Z') || ('0' <= end && end <= '9'))) {
j--;
} else if (Character.toLowerCase(start) == Character.toLowerCase(end)) {
i++;
j--;
} else {
return false;
}
}
return true;
}
}