forked from hijiangtao/LeetCode-with-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathres.ts
More file actions
25 lines (20 loc) · 641 Bytes
/
res.ts
File metadata and controls
25 lines (20 loc) · 641 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function isInterleave(s1: string, s2: string, s3: string): boolean {
if (s3.length !== (s2.length+s1.length)) {
return false;
}
if (s3.length == 1) {
return s3 === s2 || s1 === s3;
} else if (s3.length === 0) {
return s1 === s2 && s1 === '';
}
const lastS1 = s1[s1.length-1];
const lastS2 = s2[s2.length-1];
const lastS3 = s3[s3.length-1];
if (lastS3 === lastS1 && isInterleave(s1.slice(0,-1), s2, s3.slice(0,-1), )) {
return true;
}
if (lastS3 === lastS2 && isInterleave(s1, s2.slice(0,-1), s3.slice(0,-1), )) {
return true;
}
return false;
};