Created
May 3, 2020 10:31
-
-
Save Desolve/9651f4de798ee3f0de7483dfa602687f to your computer and use it in GitHub Desktop.
0680 Valid Palindrome II
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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