Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. dp = [True] + [False]*len(s)
  2. for idx1, ch1 in enumerate(p):
  3. if ch1=='*':
  4. for idx2 in range(1, len(s)+1):
  5. dp[idx2] = (dp[idx2 - 1] and (p[idx1 - 1] == '.' or p[idx1 - 1] == s[idx2 - 1])) or dp[idx2]
  6. dp[0] = (ch1 == '*') and dp[0]
  7. else:
  8. if not (idx1 < len(p)-1 and p[idx1+1] =='*'):
  9. for idx2 in range(len(s), 0, -1):
  10. dp[idx2] = dp[idx2-1] and (ch1=='.' or ch1==s[idx2-1])
  11. dp[0] = (ch1 == '*') and dp[0]
  12. return dp[-1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement