Distinct Subsequences II LeetCode solution in Python

1
class Solution:
2
def distinctSubseqII(self, s: str) -> int:
3
# number of subsequences that startwith each alphabet
4
startwith = [0] * 26
5
for c in s[::-1]:
6
startwith[ord(c) - ord("a")] = sum(startwith) + 1
7
return sum(startwith) % (10**9 + 7)

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0