Skip to content

Commit aa887b4

Browse files
authored
Merge pull request vJechsmayr#202 from PushpikaWan/0044-Wildcard-Matching
0044 - Wildcard Matching vJechsmayr#109
2 parents dd0aa34 + cfc3426 commit aa887b4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

LeetCode/0044_Wildcard_Matching.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution:
2+
def isMatch(self, s: str, p: str) -> bool:
3+
#this is a dynamic programming solution fot this
4+
matrix = [[False for x in range(len(p) + 1)] for x in range(len(s) + 1)]
5+
matrix[0][0] = True
6+
7+
for i in range(1,len(matrix[0])):
8+
if p[i-1] == '*':
9+
matrix[0][i] = matrix[0][i-1]
10+
11+
for i in range(1, len(matrix)):
12+
for j in range(1, len(matrix[0])):
13+
if s[i - 1] == p[j - 1] or p[j - 1] == '?':
14+
matrix[i][j] = matrix[i-1][j-1]
15+
elif p[j-1] == '*':
16+
matrix[i][j] = matrix[i][j-1] or matrix[i-1][j]
17+
else:
18+
matrix[i][j] = False
19+
return matrix[len(s)][len(p)]

0 commit comments

Comments
 (0)