C++ 5lines code


#1

int Solution::isInterleave(string a, string b, string c) {
if(a.empty()&&b.empty() && c.empty()) return 1;
if(c.empty())return 0;
bool first=(!a.empty()and a[0]==c[0] and isInterleave(a.substr(1),b,c.substr(1)));
bool second=(!b.empty()and b[0]==c[0] and isInterleave(a,b.substr(1),c.substr(1)));
return first||second;
}


#2

No, but it’s of exponential time complexity