The test case ("a",".*..a*") and its output is true, my local output is false. Can not understand.


  • 0
    M

    bool isMatch(char *s, char *p)
    {
    int sindex;

    if(strlen(p) == 0 && strlen(s) == 0)
    {
        return true;
    }
    
    if((strlen(s) !=0 && strlen(p) ==0))
    {
        return false;
    }
    
    if(strcmp(s,p)==0)
    {
        return true;
    }
    
    if(p[1] == '*')
    {
    
        for(sindex=0;sindex<=strlen(s);sindex++)
        {
    
            if(isMatch(s+sindex,p+2))
            {
                return true;
            }
    
            if(p[0] == '.' || s[sindex] == p[0])
            {
                continue;
            }else
            {
                break;
            }
    
        }
    
    }else
    {
        if(p[0] == '.' || p[0] == s[0])
        {
            return true && isMatch(s+1,p+1);
        }
    }
    
    return false;
    

    }


  • 0
    Y

    I seems that this is a bad case.


Log in to reply
 

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