Last active
February 15, 2017 22:34
-
-
Save xiaq/413fdf1c867bbfab2c0153734462fa42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def isCharMatch(s, p): | |
| return p in ('.', s) | |
| def isMatch(s, p): | |
| if p == '': | |
| return s == '' | |
| elif len(p) == 1: | |
| return len(s) == 1 and isCharMatch(s, p) | |
| if p[-1] != '*': | |
| return s != '' and isCharMatch(s[-1], p[-1]) and isMatch(s[:-1], p[:-1]) | |
| return (isMatch(s, p[:-2]) or | |
| (s != '' and isCharMatch(s[-1], p[-2]) and isMatch(s[:-1], p))) | |
| class Solution(object): | |
| def isMatch(self, s, p): | |
| return isMatch(s, p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment