1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| class Solution(object): def isSubsequence(self, s, t): """ :type s: str :type t: str :rtype: bool """ lenS = len(s) lenT = len(t) if lenS > lenT: return False dp = [[0]*(lenT+1) for i in range(lenS+1)] for i in range(1, lenS+1): for j in range(1, lenT+1): if s[i-1] == t[j-1]: dp[i][j] = dp[i-1][j-1]+1 else: dp[i][j] = dp[i][j-1] if dp[lenS][lenT] == lenS: return True return False
|