class Solution {
public:
bool dfs(string& s,string& t,int L,int R){
if(L == s.length()) return true;
if(R == t.length()) return false;
if(s[L] == t[R]) return dfs(s,t,L+1,R+1);
return dfs(s,t,L,R+1);
}
bool isSubsequence(string s, string t) {
return dfs(s,t,0,0);
}
};
No.47 - LeetCode392
最新推荐文章于 2022-08-09 21:05:54 发布
本文深入探讨了子序列判断算法的实现,通过递归深度优先搜索(DFS)的方法,检查字符串s是否为字符串t的子序列。算法首先比较两字符串的首字符,若相等则递归检查剩余部分;若不等,则只对t进行递归,直至遍历完所有可能。
1131

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



