题解 | #交织子序列#
交织子序列
https://www.nowcoder.com/practice/3885d44d77f34f1c89dc05ac40207f5d
直接递归 C++
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @param x string字符串 * @param t string字符串 * @return bool布尔型 */ bool fun(string &s, string &x, string &t){ if(s.size()!=0&&t[0]==s[0]){ if(isInterleave(s.substr(1,s.size()-1),x,t.substr(1,t.size()-1))) return true; } if(x.size()!=0&&t[0]==x[0]){ if(isInterleave(s,x.substr(1,x.size()-1),t.substr(1,t.size()-1))) return true; } if(t.size()==0&&s.size()==0&&t.size()==0) return true; else return false; } bool isInterleave(string s, string x, string t) { return fun(s,x,t); } };