class Solution:
# @return an integer
def numDistinct(self, S, T):
s=len(S)
t=len(T)
dp=[[0 for j in range(s+1)] for i in range(t+1)]
for j in range(s+1):
dp[0][j]=1
for j in range(1,s+1):
for i in range(1,min(j+1,t+1)):
if T[i-1]!=S[j-1]:
dp[i][j]=dp[i][j-1]
else:
dp[i][j]=dp[i-1][j-1]+dp[i][j-1]
return dp[t][s]
Friday, September 12, 2014
Leetcode: Distinct Subsequences @Python
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment