Skip to content

Commit 9be99bc

Browse files
authored
regex_matching_leetcode10
Initial File
1 parent 31e19f3 commit 9be99bc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

regex_matching_leetcode10

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)