题解 | #判断子序列#
判断子序列
https://www.nowcoder.com/practice/39be6c2d0a9b4c30a7b04053d5960a84
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param S string字符串 # @param T string字符串 # @return bool布尔型 # class Solution: def isSubsequence(self , S: str, T: str) -> bool: # write code here s_size=len(S) t_size=len(T) dp=[[0 for i in range(t_size+1)] for j in range(s_size+1)] dp[0][0]=1 for i in range(t_size+1): dp[0][i]=1 for i in range(1,s_size+1): for j in range(1,t_size+1): if(S[i-1]==T[j-1]): dp[i][j]=dp[i-1][j-1] or dp[i][j-1] else: dp[i][j]=dp[i][j-1] print('i',i,'j',j) if(dp[s_size][t_size]): return True return False