标签:solution https ref false problems rom mic val png
**官方思路
代码
public boolean validPalindrome(String s) {
int low = 0, high = s.length() - 1;
while (low < high) {
char c1 = s.charAt(low), c2 = s.charAt(high);
if (c1 == c2) {
low++;
high--;
} else {
boolean flag1 = true, flag2 = true;
for (int i = low, j = high - 1; i < j; i++, j--) {
char c3 = s.charAt(i), c4 = s.charAt(j);
if (c3 != c4) {
flag1 = false;
break;
}
}
for (int i = low + 1, j = high; i < j; i++, j--) {
char c3 = s.charAt(i), c4 = s.charAt(j);
if (c3 != c4) {
flag2 = false;
break;
}
}
return flag1 || flag2;
}
}
return true;
}
标签:solution https ref false problems rom mic val png
原文地址:https://www.cnblogs.com/yh-simon/p/12919924.html