算是最长公共子序列问题吧,mark一下
class Solution { public: bool f[1000][1000]; bool isInterleave(string s1, string s2, string s3) { if(s1.size() + s2.size() != s3.size()) return false; f[0][0] = true; for(int i = 1; i <= s1.size(); i++) f[i][0] = f[i-1][0] && (s3[i-1] == s1[i-1]); for(int j = 1; j <= s2.size(); j++) f[0][j] = f[0][j-1] && (s3[j-1] == s2[j-1]); for(int i = 1; i <= s1.size(); i++) for(int j = 1; j <= s2.size(); j++) f[i][j] = (f[i][j-1] && s2[j-1] == s3[i+j-1]) || (f[i-1][j] && s1[i-1] == s3[i+j-1]); return f[s1.size()][s2.size()]; } };
leetcode Interleaving String,布布扣,bubuko.com
原文地址:http://blog.csdn.net/sina012345/article/details/38737551