Skip to content

Instantly share code, notes, and snippets.

@s4553711
Created February 1, 2018 14:09
Show Gist options
  • Save s4553711/21eaa3e38e85b09b861db72f27948e59 to your computer and use it in GitHub Desktop.
Save s4553711/21eaa3e38e85b09b861db72f27948e59 to your computer and use it in GitHub Desktop.
class Solution {
public:
bool validPalindrome(string s) {
return valid(s, 0, s.length() - 1, 1);
}
bool valid(string& s, int i, int j, int d) {
if (i >= j) return true;
if (s[i] == s[j])
return valid(s, i + 1, j - 1, d);
else
return d > 0 && (valid(s, i + 1, j, d - 1) || valid(s, i, j - 1, d - 1));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment