680. 验证回文字符串 Ⅱ
class Solution {
public boolean validPalindrome(String s) {
int left = 0;
int right = s.length() - 1;
while (left <= right) {
if (s.charAt(left) == s.charAt(right)) {
++left;
--right;
} else {
return judge(s, left, right - 1) || judge(s, left + 1, right);
}
}
return true;
}
private boolean judge(String s, int left, int right) {
while (left <= right) {
if (s.charAt(left) == s.charAt(right)) {
++left;
--right;
} else {
return false;
}
}
return true;
}
}