双指针夹逼,也只能1ms,未想到0ms的方法
class Solution {
public static boolean isPalindrome(String s) {
int i = -1, j = s.length();
char si,sj;
while(++i < --j){
si = s.charAt(i);
sj = s.charAt(j);
if(isus(si)) si = (char) (si + 32);
if(isus(sj)) sj = (char) (sj + 32);
if (islsornum(si) && islsornum(sj)) {
if(si != sj) return false;
} else if(islsornum(si)) {
i--;
} else if(islsornum(sj)) {
j++;
}
}
return true;
}
public static boolean islsornum(char c) {
return c >= 'a' && c <= 'z' || (c >= '0' && c <= '9');
}
public static boolean isus(char c) {
return c >= 'A' && c <= 'Z';
}
}