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.
1 parent 31e19f3 commit 9be99bcCopy full SHA for 9be99bc
regex_matching_leetcode10
@@ -0,0 +1,24 @@
1
+def isMatch(text, pattern):
2
+ m, n = len(text), len(pattern)
3
+
4
+ dp = [[False for _ in range(n+1)] for _ in range(m+1)]
5
+ dp[0][0] = True
6
+ for i in range(1,n+1):
7
+ if pattern[i-1]=='*':
8
+ dp[0][i]=dp[0][i-2]
9
+ for i in range(1, n+1):
10
+ for j in range(1, m+1):
11
+ if text[i-1] == pattern[j-1] or pattern[j-1] == '.':
12
+ dp[i][j] = dp[i - 1][j - 1]
13
+ elif pattern[j-1] == '*':
14
+ dp[i][j] = dp[i][j - 2]
15
+ if text[i-1] == pattern[j - 2] or pattern[j-2]=='.':
16
+ dp[i][j] = dp[i - 1][j]
17
+ else:
18
+ dp[i][j] = False
19
20
+ return dp[m][n]
21
22
+A='yccfdv'
23
+B='yc*f.g'
24
+print(isMatch(A, B))
0 commit comments