Why the same code give different results between my computer(VS-2010) and LeetCode OJ?


  • 0
    C

    when I use testcase s="aa",p="a*",my computer return "true" while LeetCode OJ return "false"?Why?
    mycode:
    class Solution {
    public:

    bool isMatch(string s, string p)
    {
    
    	if('\0'==p[0])
    		return '\0'==s[0];
    	if('*'==p[0])
    		return false;   
    
    	if('*' !=  p[1])//next character is  not '*'
    	{
    		if('\0'==s[0])
    		{ 
    			return false;
    		}
    		else if('.'==p[0] || s[0]==p[0])
    		{
    			return isMatch(s.substr(1),p.substr(1));
    		}
    		else// if(s[0]!=p[0])
    		{
    			return false;
    		}
    	}
    	else//next character is  '*'
    	{
    		for(int i=0;i<s.length();i++)
    		{
    			if( isMatch(s.substr(i),p.substr(2) ) )
    				return true;
    			if('.'==p[0] || s[i]==p[0])
    				continue;
    			else
    				return false;
    		}
    	}
    }
    

    };


Log in to reply
 

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