class Solution {
public:
bool isSubsequence(string s, string t)
{
int m=s.length();
int n=t.length();
bool dp[m+1][n+1];
for(int j=0;j<=n;j++)
{
dp[0][j]=true;
}
for(int i=1;i<=m;i++)
{
for(int j=i;j<=n;j++)
{
if(s[i - 1] == t[j - 1]) { //由于i-1即第i个
dp[i][j] = dp[i - 1][j - 1];
} else {
dp[i][j] = dp[i][j - 1];
}
if(i == m && dp[i][j] == true) return true; //剪枝
}
}
}
};
动态规划 --- 392 .判断子序列
最新推荐文章于 2024-03-09 13:39:59 发布