看了大佬思路的暴力递归,还有待优化:
class Solution:
def isMatch(self, s: str, p: str) -> bool:
def ism(s,p):
if p=='':
if s=='':
return True
else:
return False
f_match=bool(s) and p[0] in {'.',s[0]}
if len(p)>=2 and p[1]=='*':
return ism(s,p[2:]) or (f_match and ism(s[1:],p))
else:
return f_match and ism(s[1:],p[1:])
return ism(s,p)