Skip to content

Commit f40dd38

Browse files
Leetcode solution added for 44 in cpp
1 parent bc48a25 commit f40dd38

File tree

1 file changed

+35
-0
lines changed
  • leetcode/cpp/dynamic programming

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Solution {
2+
public:
3+
bool isMatch(string s, string p) {
4+
int m=s.length();
5+
int n=p.length();
6+
int i,j;
7+
int dp[m+1][n+1];
8+
memset(dp,0,sizeof(dp));
9+
for(i=0;i<=m;i++)
10+
{
11+
for(j=0;j<=n;j++)
12+
{
13+
if(i==0 && j==0)
14+
dp[i][j]=1;
15+
else if(j==0)
16+
dp[i][j]=0;
17+
else if(i==0)
18+
{
19+
if(p[j-1]=='*')
20+
dp[i][j]=dp[i][j-1];
21+
}
22+
else
23+
{
24+
if(s[i-1]==p[j-1] || p[j-1]=='?')
25+
dp[i][j]=dp[i-1][j-1];
26+
else if(p[j-1]=='*')
27+
dp[i][j]=dp[i-1][j]||dp[i][j-1];
28+
else
29+
dp[i][j]=0;
30+
}
31+
}
32+
}
33+
return dp[m][n];
34+
}
35+
};

0 commit comments

Comments
 (0)