class Solution {
public:
bool isInterleave(string s1, string s2, string s3) {
if(s1=="")
return s2==s3;
if(s2=="")
return s1==s3;
int n=s1.size();
int m=s2.size();
if(s3.size()!=(m+n))
return false;
vector<vector<int>> dp(n+1,vector<int>(m+1,0));
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
if(i==0&&j==0){
dp[0][0]=1;
}
else if(i==0){
if(s3[j-1]==s2[j-1]&&dp[0][j-1]){
dp[0][j]=1;
}
}
else if(j==0){
if(s3[i-1]==s1[i-1]&&dp[i-1][0]){
dp[i][0]=1;
}
}
else{
if((s1[i-1]==s3[i+j-1]&&dp[i-1][j])||(s2[j-1]==s3[i+j-1]&&dp[i][j-1])){
dp[i][j]=1;
}
}
}
}
return dp[n][m];
}
};
08-20
121
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)