题目:
题解:
class Solution:def isMatch(self, s: str, p: str) -> bool:def allStars(st: str, left: int, right: int) -> bool:return all(st[i] == '*' for i in range(left, right))def charMatch(u: str, v: str) -> bool:return u == v or v == '?'sRight, pRight = len(s), len(p)while sRight > 0 and pRight > 0 and p[pRight - 1] != '*':if charMatch(s[sRight - 1], p[pRight - 1]):sRight -= 1pRight -= 1else:return Falseif pRight == 0:return sRight == 0sIndex, pIndex = 0, 0sRecord, pRecord = -1, -1while sIndex < sRight and pIndex < pRight:if p[pIndex] == '*':pIndex += 1sRecord, pRecord = sIndex, pIndexelif charMatch(s[sIndex], p[pIndex]):sIndex += 1pIndex += 1elif sRecord != -1 and sRecord + 1 < sRight:sRecord += 1sIndex, pIndex = sRecord, pRecordelse:return Falsereturn allStars(p, pIndex, pRight)