Notes:
1. Even S3 is the empty string, if S1 and S2 are emtpy, then it should BES is true.
2. Do not mess the size of the label.
1 classSolution {2 Public:3 BOOLIsinterleave (stringS1,stringS2,stringS3) {4 intL1 = S1.size (), L2 = S2.size (), L3 =s3.size ();5 if(L3! = L2 + L1)return false;6vector<vector<BOOL> > DP (l1+1, vector<BOOL> (l2+1,false));7dp[0][0] =true;8 for(inti =1; I <= L1; i++) dp[i][0] = dp[i-1][0] && s1[i-1] = = s3[i-1];9 for(inti =1; I <= L2; i++) dp[0][i] = dp[0][i-1] && s2[i-1] = = s3[i-1];Ten for(inti =1; I <= L1; i++) { One for(intj =1; J <= L2; J + +) { ADP[I][J] = ((dp[i-1][J] && s1[i-1] = = s3[i+j-1]) || -(dp[i][j-1] && s2[j-1] = = s3[i+j-1]) || -(dp[i-1][j-1] && s1[i-1] = = s3[i+j-1] && s2[j-1] = = s3[i+j-2]) || the(dp[i-1][j-1] && s1[i-1] = = s3[i+j-2] && s2[j-1] = = s3[i+j-1])); - } - } - returnDP[L1][L2]; + } -};
Leetcode–refresh–interleaving String