class Solution {
public:
bool isInterleave(string s1, string s2, string s3) {
int sz1 = s1.size();
int sz2 = s2.size();
int sz3 = s3.size();
if (sz1 + sz2 != sz3) {
return false;
}
auto dp = std::vector<std::vector<int>>(sz1 + 1, std::vector<int>(sz2 + 1, false));
dp[0][0] = true;
for (int i = 0; i <= sz1; ++i) {
for (int j = 0; j <=sz2; ++j) {
int k = i + j - 1;
if (i > 0) {
dp[i][j] |= (dp[i - 1][j] &&(s1[i - 1] == s3[k]));
}
if (j > 0) {
dp[i][j] |= (dp[i][j - 1] && (s2[j - 1] == s3[k]));
}
}
}
return dp[sz1][sz2];
}
};
class Solution {
public:
bool isInterleave(string s1, string s2, string s3) {
int sz1 = s1.size();
int sz2 = s2.size();
int sz3 = s3.size();
if (sz1 + sz2 != sz3) {
return false;
}
auto dp = std::vector<std::vector<bool>>(sz1 + 1, std::vector<bool>(sz2 + 1, false));
dp[0][0] = true;
for (int i = 1; i <= sz1; ++i) {
dp[i][0] = (dp[i - 1][0] && (s1[i - 1] == s3[i - 1]));
}
for (int j = 1; j <= sz2; ++j) {
dp[0][j] = (dp[0][j - 1] && (s2[j - 1] == s3[j - 1]));
}
for (int i = 1; i <= sz1; ++i) {
for (int j = 1; j <=sz2; ++j) {
int k = i + j - 1;
int con1 = (dp[i - 1][j] &&(s1[i - 1] == s3[k]));
int con2 = (dp[i][j - 1] && (s2[j - 1] == s3[k]));
dp[i][j] = (con1 || con2);
}
}
return dp[sz1][sz2];
}
};
???????