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 da60996 commit 019b886Copy full SHA for 019b886
10/10.py
@@ -0,0 +1,27 @@
1
+class Solution:
2
+ def isMatch(self, s: str, p: str) -> bool:
3
+
4
+ cache = dict()
5
6
+ def helper(i, j):
7
+ if((i,j) in cache):
8
+ return cache[(i, j)]
9
+ if(i >= len(s) and j >= len(p)):
10
+ return True
11
+ elif(j >= len(p)):
12
+ return False
13
14
+ charMatch = i < len(s) and (s[i] == p[j] or p[j] == '.')
15
+ if j + 1 < len(p) and p[j + 1] == '*':
16
+ cache[(i, j)] = helper(i, j + 2) or (charMatch and helper(i + 1, j))
17
18
19
+ if charMatch:
20
+ cache[(i, j)] = helper(i + 1, j + 1)
21
22
23
+ cache[(i, j)] = False
24
25
26
+ return helper(0,0)
27
0 commit comments