Online judge is wrong


  • -1
    R

    @Shangrila, why did you delete my question? Didn't I describe the OJ issue clearly? This looks like a bug in OJ.

    For sample test case s="aa", p="a*", the below solution works perfectly on visual studio 2010, it returns true. But OJ says it returns false.

    bool isMatch(const char *s, const char *p) {
    
        const char* star=0;
        while (*s){
            if ((*p=='?')||(*p==*s)){
                s++;
                p++;
                continue;
            }
            else if (*p=='*'){
                star=p;
                p++;
                continue;
            }
            else if (star){ 
                p = star+1; 
                if(!*++s){
                    if(!*p) {
                        p++;
                    }
                }
                continue;
            }
            return false;
        }
        while (*p=='*'){
            p++;
        }
        return !*p;
    }

  • 0

    Most likely it is a bug on your side. Please read the FAQ (https://oj.leetcode.com/faq/), especially the question: "Why does my code produce a different output compared to my local environment?"


  • 0

    By the way, you could test out here (it returns false for case s="aa", p="a*":
    http://codepad.org/Ts3ugbQv

    This means your code had hit an undefined error which could lead to different result in different environments, possibly due to invalid memory access.


Log in to reply
 

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