An easy task, even no using of DP, just increase the t counter when different or increase both when same.
class Solution {
public:
bool isSubsequence(string s, string t) {
int i=0,j=0;
while(j<t.length()){
if(s[i]==t[j]){
i++;
j++;
}
else
j++;
}
if(i==s.length())
return true;
else
return false;
}
};
子序列判断算法
本文介绍了一种简单的方法来判断一个字符串是否为另一个字符串的子序列。通过遍历两个字符串并比较字符,该方法能高效地得出结论。文章提供了一个C++实现示例。
877

被折叠的 条评论
为什么被折叠?



