1 class Solution {
2 public:
3 bool isInterleave(string s1, string s2, string s3) {
4 // Start typing your C/C++ solution below
5 // DO NOT write int main() function
6 if(s1.size()==0&&s2.size()==0&&s3.size()==0)
7 return true;
8 if(s1.size()+s2.size()!=s3.size())
9 return false;
10
11 if(s1.size()==1&&s2.size()==0&&s3.size()==1)
12 {
13 if(s1[0]==s3[0])
14 return true;
15 return false;
16 }
17
18 if(s2.size()==1&&s1.size()==0&&s3.size()==1)
19 {
20 if(s2[0]==s3[0])
21 return true;
22 return false;
23 }
24
25
26 if(s1.size()!=0&&s1[0]==s3[0]&&isInterleave(s1.substr(1,s1.size()-1),s2,s3.substr(1,s3.size()-1)))
27 return true;
28 if(s2.size()!=0&&s2[0]==s3[0]&&isInterleave(s1,s2.substr(1,s2.size()-1),s3.substr(1,s3.size()-1)))
29 return true;
30
31
32 return false;
33 }
34 };
//大数据测试会超时