My 20ms c solution in 10 lines


  • 3
    D
    bool isMatch(char* s, char* p) {
        while (*s) {
            if (*p&&*(p+1)=='*') {
                if (!(*p==*s||*p=='.')) {p+=2;continue;} 
                if (!isMatch(s,p+2)) {s++;continue;} else return true;
            }
            if (*p==*s||*p=='.') {s++;p++;continue;}
            return false;
        }
        while(*p&&*(p+1)=='*') p+=2;
        return !*p;
    

    }


  • 0
    A

    Gangshen is very niubi,I am your fans


Log in to reply
 

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