leetcode刷题python之通配符匹配

class Solution:
    def isMatch(self, s: str, p: str) -> bool:
        i = 0 
        j = 0
        start = -1
        match = 0
        while i < len(s):
            if j < len(p) and ( s[i] == p[j] or p[j] == '?' ):
                i += 1
                j += 1
            elif j < len(p) and p[j] == '*':
                start = j
                match = i
                j += 1
            elif start != -1:
                j = start
                match += 1
                i = match
            else:
                return False
        return all(x == '*' for x in p[j:]) 

你可能感兴趣的:(leetcode_python)