125. 验证回文串
小于 1 分钟
125. 验证回文串中等
解法:双指针
class Solution {
public boolean isPalindrome(String s) {
if (s.trim().equals("")) return true;
int left = 0,right = s.length() - 1;
while(left <= right) {
int l = s.charAt(left);
int r = s.charAt(right);
if(!((l >= 48 && l < 58) || (l >= 65 && l < 91) || (l >= 97 && l < 123))) {
left++;
}else if(!((r >= 48 && r < 58) || (r >= 65 && r < 91) || (r >= 97 && r < 123))) {
right--;
}else if(l == r || (Math.min(l, r) >= 65 && (l == r + 32)) || (Math.min(l, r) >= 65 && (r == l + 32))) {
left++;
right--;
}else {
return false;
}
}
return true;
}
}
Powered by Waline v2.15.5