C++ O(n) recursive solutuon

  • 0
        bool flag=false;
        bool validPalindrome(string s) {
            return check(s, 0, s.size()-1);
        bool check(string &str, int s, int e) {
            while(s<e) {
                if(str[s]!=str[e]) {
                    if(flag) return false;
                    else {
                        return check(str, s+1, e)||check(str, s, e-1);
                s++, e--;
            return true;

Log in to reply

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