美文网首页
10. Regular Expression Matching

10. Regular Expression Matching

作者: chaowwwww | 来源:发表于2018-04-10 20:01 被阅读0次
class Solution:
    def isMatch(self, s, p):
        """
        :type s: str
        :type p: str
        :rtype: bool
        """
        if p == '':
            if s == '':
                return True
            else:
                return False
        first_match = bool(s) and p[0] in {s[0], '.'}
        if len(p) > 1 and p[1] == '*':
            return self.isMatch(s, p[2:]) or \
                   first_match and self.isMatch(s[1:], p)
        else:
            return first_match and self.isMatch(s[1:],p[1:])

相关文章

网友评论

      本文标题:10. Regular Expression Matching

      本文链接:https://www.haomeiwen.com/subject/cranhftx.html