File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ bool isInterleave (string s1, string s2, string s3) {
4
+ if (s1.length () + s2.length () != s3.length ()) {
5
+ return false ;
6
+ }
7
+
8
+ std::vector<std::vector<char >> memo (1 + s1.length (), std::vector<char >(1 + s2.length (), -1 ));
9
+
10
+ std::function<bool (int ,int )> go = [&](int a, int b) -> bool {
11
+
12
+ int c = a + b;
13
+ if (c >= static_cast <int >(s3.length ())) {
14
+ return true ;
15
+ }
16
+
17
+ char & ret = memo[a][b];
18
+ if (ret != -1 ) {
19
+ return ret;
20
+ }
21
+
22
+ ret = false ;
23
+
24
+ ret |= (a < static_cast <int >(s1.length ()) && s3[c] == s1[a] && go (a+1 , b));
25
+ ret |= (b < static_cast <int >(s2.length ()) && s3[c] == s2[b] && go (a, b+1 ));
26
+
27
+ return ret;
28
+ };
29
+
30
+ return go (0 ,0 );
31
+ }
32
+ };
You can’t perform that action at this time.
0 commit comments