upd
This commit is contained in:
1
algorithms/labs/lab6/leetcode/1/link.txt
Normal file
1
algorithms/labs/lab6/leetcode/1/link.txt
Normal file
@@ -0,0 +1 @@
|
||||
https://leetcode.com/problems/regular-expression-matching/submissions/1769086671/?envType=problem-list-v2&envId=dynamic-programming
|
||||
14
algorithms/labs/lab6/leetcode/1/solution.py
Normal file
14
algorithms/labs/lab6/leetcode/1/solution.py
Normal file
@@ -0,0 +1,14 @@
|
||||
class Solution:
|
||||
def isMatch(self, s: str, p: str) -> bool:
|
||||
from functools import lru_cache
|
||||
|
||||
@lru_cache(None)
|
||||
def dp(i: int, j: int) -> bool:
|
||||
if j == len(p):
|
||||
return i == len(s)
|
||||
first = i < len(s) and (p[j] == s[i] or p[j] == ".")
|
||||
if j + 1 < len(p) and p[j + 1] == "*":
|
||||
return dp(i, j + 2) or (first and dp(i + 1, j))
|
||||
return first and dp(i + 1, j + 1)
|
||||
|
||||
return dp(0, 0)
|
||||
Reference in New Issue
Block a user