Skip to content

Instantly share code, notes, and snippets.

@Desolve
Created May 3, 2020 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Desolve/9651f4de798ee3f0de7483dfa602687f to your computer and use it in GitHub Desktop.
Save Desolve/9651f4de798ee3f0de7483dfa602687f to your computer and use it in GitHub Desktop.
0680 Valid Palindrome II
class Solution {
public boolean validPalindrome(String s) {
char[] arr = s.toCharArray();
for (int i = 0, j = arr.length - 1; i < j; ++i, --j)
if (arr[i] != arr[j]) return isp(arr, i + 1, j) || isp(arr, i, j - 1);
return true;
}
private boolean isp(char[] arr, int l, int r) {
for (; l < r; ++l, --r)
if (arr[l] != arr[r]) return false;
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment