I get RUNTIME ERROR for testcase "bacccabbaacaccabac" ".*..*.*c*.a*bb*b*" but it runs correctly on my system ?


  • 0
    B
    vector< vector<int> > vec;
    bool isMatch1(string s, string p,int i, int j)
    {	 bool b1,b2;			
         if(s.length()==i && p.length==j)
    	 {		vec[i][j]=1;
    	        return true;
    	 }
    	 if(p[j]=='*')
    	 {			
    		if((p[j-1] == s[i] || p[j-1] == '.') && i<s.length())
    		{
    			if(vec[i+1][j]==-1)
    			{
    				b1 = isMatch1(s,p,i+1,j);
    				vec[i+1][j]=b1;					
    				if(b1)
    				return b1;
    			}
    			else
    				b1 = vec[i+1][j];
    			if(vec[i][j+1]==-1)				
    			{
    				b2 = isMatch1(s,p,i,j+1);				
    				vec[i][j+1] = b2;
    			}
    			else
    				b2 = vec[i][j+1];			
    			return (b1||b2);
    		}
    		else
    		{
    			if(vec[i][j+1]==-1)				
    			   vec[i][j+1]=isMatch1(s,p,i,j+1);
    			return vec[i][j+1];
    		}
    	 }    	 
    	 if((s[i]==p[j] || p[j]=='.') && p[j+1]!='*' && p[j]!='*' && i < s.length())
    	 {		
    		if(vec[i+1][j+1]==-1)
    	        vec[i+1][j+1]=isMatch1(s,p,i+1,j+1);    	        	       
    		return vec[i+1][j+1];
    	 }   		 
    	if(p[j+1]=='*')
    	{			
    		vec[i][j+1]=isMatch1(s,p,i,j+1);
    		return vec[i][j+1];
    	}		
    	vec[i][j]=false;
    	return false;
    }
    bool isMatch(string s, string p) 
    {   vector<int> v;
    	for(int i=0;i<s.length()+1;i++)
    	{
    		for(int j=0;j<=p.length();j++)
    		{
    			v.push_back(-1);
    		}
    		vec.push_back(v);
    		v.erase(v.begin(),v.end());
    	}
    	vec[s.length()][p.length()] = 1;
    	return isMatch1(s,p,0,0);	
    }

Log in to reply
 

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