100ms C++ clear recursion.


  • 0
    A
    bool isValid(string& s, int left, int right, int count){
        while(left<right){
            if(s[left]!=s[right]){
                if(count--) return isValid(s,left+1,right,count)||isValid(s,left,right-1,count);
                else return false;
            }
            left++;
            right--;
        }
        return true;
    }
    bool validPalindrome(string s) {
        return isValid(s,0,s.size()-1,1);
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.