my easy c++ solution


  • 0
    Q
    class Solution {
    public:
      bool isMatch(string s,string p)
      {int dp[100][100];
    	memset(dp,0,sizeof(dp));
    	dp[0][0]=1;
    	for(int j=1;j<=p.length();j++)
    	{
    		int i =1;
    		while(i<=s.length()+1)
    		{
    			if(p[j-1]=='*')
    			{
    				
    				if(dp[i-1][j-2])
    				{
    					dp[i-1][j]=1;
    					i++;
    					while(i<=s.length()+1&&(s[i-2]==p[j-2]||p[j-2]=='.'))
    					{
    						dp[i-1][j]=1;
    						i++;
    					}
    
    				}else i++;
    
    			}else
    			{
    				if(s[i-1]==p[j-1]||p[j-1]=='.'){ dp[i][j] = dp[i-1][j-1];}
    				i++;
    			}
    			
    		}
    		
    	}
    
    	return dp[s.length()][p.length()];
          
      }
      
    
    
    };
    

  • 0
    Q
    This post is deleted!

Log in to reply
 

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