看家本领不能丢,准备2021年每天一道leetcode题目,尽量不间隔,Python3.8
class Solution:
def isMatch(self, s: str, p: str) -> bool:
@lru_cache(None)
def recur(i,j):
if j==len(p): return i==len(s)
first_match = (len(s) > i) and (p[j] == s[i] or p[j] == '.')
if len(p) >=j+2 and p[j+1] == '*':
return recur(i, j+2) or (first_match and recur(i+1, j))
return first_match and recur(i+1, j+1)
return recur(0,0)