We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 9052720 + f40dd38 commit 1eb07d6Copy full SHA for 1eb07d6
leetcode/cpp/dynamic programming/44.cpp
@@ -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
29
30
31
32
33
+ return dp[m][n];
34
35
+};
0 commit comments