- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDistinctSubsequences.py
More file actions
Latest commit
28 lines (26 loc) · 828 Bytes
/
Copy pathDistinctSubsequences.py
File metadata and controls
28 lines (26 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#S="adbdadeecadeadeccaeaabdabdbcdabddddabcaaadbabaaedeeddeaeebcdeabcaaaeeaeeabcddcebddebeebedaecccbdcbcedbdaeaedcdebeecdaaedaacadbdccabddaddacdddc"
#T="bcddceeeebecbc"
S="babgbag"
T="bag"
classSolution:
defnumDistinct(self, s: str, t: str) ->int:
row1=[]
row2=[]
m=len(t)+1
n=len(s)+1
foriinrange(m):
forjinrange(n):
ifi==0:
row1.append(1)
continue
ifj==0:
row1.append(0)
continue
ift[i-1]==s[j-1]:
row1.append(row1[j-1]+row2[j-1])
else:
row1.append(row1[j-1])
row2=row1[:]
row1.clear()
return(row2[-1])
print(Solution().numDistinct(S,T))