/
Valid Palindrome.java
31 lines (28 loc) · 1001 Bytes
/
Valid Palindrome.java
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
30
31
class Solution {
public boolean isPalindrome(String s) {
if(s.length()==0)
return true;
s = s.toUpperCase();
int low1 = 'A', high1 = 'Z';
int low2 = '0', high2 = '9';
int low = 0, high = s.length()-1;
while(low < high){
if((s.charAt(low)<low1||s.charAt(low)>high1)
&& (s.charAt(low)<low2||s.charAt(low)>high2)){
low++;
continue;
}
if((s.charAt(high)<low1||s.charAt(high)>high1)
&& (s.charAt(high)<low2||s.charAt(high)>high2)){
high--;
continue;
}
if(s.charAt(low) == s.charAt(high)){
low++;
high--;
}else
return false;
}
return true;
}
}