A simple C solution[Accepted]


  • 0
    B
    bool isValidPalindrome(char* s,int len){
        if(len==1||(len==3&&s[0]==s[2])||(len==2&&s[0]==s[1])){return true;}
        for(int i=0;i<len/2;i++){
            if(s[i]!=s[len-i-1]){return false;}
        }
        return true;
    }
    bool validPalindrome(char* s) {
        int len=strlen(s);
        for(int i=0;i<len/2;i++){
            if(s[i]!=s[len-i-1]){
                   return  isValidPalindrome(&s[i],len-2*i-1)||isValidPalindrome(&s[i+1],len-2*i-1);     
            }
        }
        return true;
    }
    

Log in to reply
 

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