Got different results from leetcode.


  • 0
    T

    My PC returns true for test case "a", "ab*".
    However, leetcode OJ returns false.
    I have no idea why. Could anyone help me?

        bool isMatch(const char *s, const char *p) {
        const char * star;
        star = NULL;
        while (*s != '\0'){
            if (*p == '.' || *s == *p){
                if (star != NULL && *s != *(star - 1))
                    star = NULL;
                s++;
                p++;
                continue;
            }
            if (*p == '*'){
                star = p;
                p++;
            }
            else if (*(p + 1) == '*')
                p += 2;
            else if (star != NULL && (*(star - 1) == '.' || *(star - 1) == *s))
                s++;
            else 
                return false;
        }
        while (*(p + 1) == '*'){p += 2;}
        return *p == '\0';        
    }

Log in to reply
 

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