时间限制:1000ms内存限制:256M
题目描述
已知一个字符串a,b。 字符串b中包含特殊符号’.’,’’。 ‘.’表示该字符可以变成任意字符,’ ‘表示该字符的前一个字符可以变成任意多个。 现在我们想知道b可否通过特殊符号变成a。
输入描述:
第一行输入字符串a.(1<=len(a)<=1000) 第二行输入字符串b.(1<=len(b)<=1000)
输出描述:
如果可以输出”yes”,否则输出’no’
class Solution:
def __init__(self) -> None:
pass
def isMatch(self,s, p):
if not p:
return not s
first_match = bool(s) and p[0] in {s[0], '.'}
if len(p) >= 2 and p[1] == '*':
result= (self.isMatch(s, p[2:]) or
first_match and self.isMatch(s[1:], p))
else:
result= first_match and self.isMatch(s[1:], p[1:])
if result==True:
return "yes"
else:
return "no"
if __name__ == "__main__":
a = input().strip()
b = input().strip()
sol = Solution()
result = sol.isMatch(a, b)
print(result)
代码通过率只有70%,不知道问题出在哪?