Guest User

Distinct Subsequences

a guest
Feb 24th, 2021
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. def numDistinct(self, s: str, t: str) -> int:
  2. l1, l2 = len(s)+1, len(t)+1
  3. cur = [0] * l2
  4. cur[0] = 1
  5. for i in range(1, l1):
  6. pre = cur[:]
  7. for j in range(1, l2):
  8. cur[j] = pre[j] + pre[j-1]*(s[i-1] == t[j-1])
  9. return cur[-1]
Advertisement
Add Comment
Please, Sign In to add comment