本文共 878 字,大约阅读时间需要 2 分钟。
class Solution(object): def isMatch(self, s, p): print(s,p,'...') i,n = 0,len(p) if s=='':return p=='' or (len(p)>=2 and p[1]=='*' and self.isMatch('',p[2:])) if p=='':return False if len(p)==1:return (s[0]==p[0] or p[0]=='.') and self.isMatch(s[1:],p[1:]) if s[-1]!=p[-1] and p[-1]!='.' and p[-1]!='*' :return False ch = p[0] if ch=='.': if p[1]=='*': j,n_s = 0,len(s) while j0 and s[j-1]!=ch):break; print(j,s,p,ch,s[j-1],n_s) res = self.isMatch(s[j:],p[2:]) if res==False:pass else:return True j+=1 return False else: return ch==s[0] and self.isMatch(s[1:],p[1:])print(Solution().isMatch("ab","a*"))
转载地址:http://jmrkn.baihongyu.com/