'?' Matches any single character.

The matching should cover the entire input string (not partial).

The function prototype should be:

Some examples:

): # p为匹配模式,s为字符串 def recursive(self, s, p, si, pi, cur): first = True n_cur = cur while si < len(s) and pi < len(p) and (s[si] == p[pi] or p[pi] == '?'): si += 1 pi += 1 if pi == len(p): return si == len(s) if p[pi] == '*': while pi < len(p) and p[pi] == '*': pi += 1 if pi >= len(p): return True for i in range(si, len(s)): # 表明开始重合,从这里再度开始递归 if p[pi] != s[i] and p[pi] != '?': continue if first: cur += 1 first = False # 可能存在多次重合但是还不算真正匹配的情况 if self.recursive(s, p, i, pi, cur + 1): return True if cur > n_cur + 1: # 正常来说n_cur = cur + 1 return False return False def isMatch(self, s, p): """ :type s: str :type p: str :rtype: bool """ return self.recursive(s, p, 0, 0, 0)

相关文章:

  • 2021-11-19
  • 2022-12-23
  • 2021-09-18
  • 2022-03-07
  • 2022-12-23
  • 2021-07-26
猜你喜欢
  • 2022-12-23
  • 2021-09-03
  • 2021-10-09
  • 2021-09-03
  • 2021-09-22
  • 2022-02-20
相关资源
相似解决方案