1
class Solution {
2
boolean first = false;
3

4
public boolean validPalindrome(String s) {
5
int left = 0;
6
int right = s.length() - 1;
7

8
while (left <= right) {
9
if (s.charAt(left) == (s.charAt(right))) {
10
left++;
11
right--;
12
} else if (!first) {
13
first = true;
14
String removeLeft = s.substring(0, left).concat(s.substring(left + 1));
15
String removeright = s.substring(0, right).concat(s.substring(right + 1));
16
left++;
17
right--;
18
return validPalindrome(removeLeft) || validPalindrome(removeright);
19
} else {
20
return false;
21
}
22
}
23
return true;
24
}
25
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0