regular expression matching --python
2017-11-10 21:20
411 查看
递归
class Solution(object): def isMatch(self, s, p): if not p: return not s if len(p) == 1 or p[1] != '*': return len(s) >0 and (p[0] == '.' or s[0] == p[0])and self.isMatch(s[1:], p[1:]) while s and (p[0] == '.' or s[0] == p[0]): if self.isMatch(s, p[2:]): return True s = s[1:] return self.isMatch(s, p[2:])
具体理解参考https://www.cnblogs.com/skysand/p/4292973.html
python自带正则表达式
def isMatch(self, s, p): return re.match('^' + p + '$', s) != None
这应该是网上的两个最简洁的解题思路了。
相关文章推荐
- python写算法题:leetcode: 10. Regular Expression Matching
- leetcode10 Regular Expression Matching @python
- 【LeetCode with Python】 Regular Expression Matching
- LeetCode 10 Regular Expression Matching (C,C++,Java,Python)
- [leetcode]Regular Expression Matching @ Python
- [LeetCode]题解(python):010-Regular Expression Matching
- leetcode problem 10 Regular Expression Matching(动态规划)
- 算法第12周Regular Expression Matching[hard]
- Leetcode: Regular Expression Matching
- LeetCode-Regular Expression Matching
- [LeetCode-Algorithms-10] "Regular Expression Matching" (2017.10.12-WEEK6)
- LeetCode : Regular Expression Matching
- Regular Expression Matching--LeetCode
- Java [leetcode 10] Regular Expression Matching
- Regular Expression Matching
- LeetCode OJ --问题与解答 Regular Expression Matching
- [Python]Regular Expression Syntax
- leetcode10-Regular Expression Matching之Java版本
- LeetCode之Regular Expression Matching
- Regular Expression Matching