Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dp = [True] + [False]*len(s)
- for idx1, ch1 in enumerate(p):
- if ch1=='*':
- for idx2 in range(1, len(s)+1):
- dp[idx2] = (dp[idx2 - 1] and (p[idx1 - 1] == '.' or p[idx1 - 1] == s[idx2 - 1])) or dp[idx2]
- dp[0] = (ch1 == '*') and dp[0]
- else:
- if not (idx1 < len(p)-1 and p[idx1+1] =='*'):
- for idx2 in range(len(s), 0, -1):
- dp[idx2] = dp[idx2-1] and (ch1=='.' or ch1==s[idx2-1])
- dp[0] = (ch1 == '*') and dp[0]
- return dp[-1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement