public class Solution {
public boolean isPalindrome(String s) {
if (s == null) {
throw new IllegalArgumentException("aa");
}
if (s.length() == 0) {
return true;
}
s = s.toLowerCase();
char dl = '0', dh = '9';
char cl = 'a', ch = 'z';
int i = 0, j = s.length() - 1;
while (i < j) {
if (!((s.charAt(i)>= dl && s.charAt(i) <= dh) ||(s.charAt(i)>= cl && s.charAt(i) <= ch))) {
i++;
continue;
}
if (!((s.charAt(j)>= dl && s.charAt(j) <= dh) ||(s.charAt(j)>= cl && s.charAt(j) <= ch))) {
j--;
continue;
}
if (s.charAt(i) == s.charAt(j)) {
i++;
j--;
} else {
return false;
}
}
return true;
}
}
Valid Palindrome
最新推荐文章于 2024-01-04 12:53:14 发布