-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ119.js
48 lines (44 loc) · 1.78 KB
/
Q119.js
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// var isSubsequence = function (s, t) {
// let allPossibility = [];
// function all(s, idx, arr, ans, empty = []) {
// if (idx >= arr.length) {
// if (empty.length === s.length) {
// ans.push([...empty]);
// }
// return;
// }
// if (empty.length > s.length) return;
// empty.push(arr[idx]);
// all(s, idx + 1, arr, ans, empty); // -----------------> Take an element
// empty.pop();
// all(s, idx + 1, arr, ans, empty); // -----------------> Not take element
// }
// all(s, 0, t.split(""), allPossibility);
// for (let i = 0; i < allPossibility.length; i++) {
// allPossibility[i] = allPossibility[i].join("");
// }
// return allPossibility.includes(s);
// };
// let s = "rjufvjafbxnbgriwgokdgqdqewn";
// t =
// "mjmqqjrmzkvhxlyruonekhhofpzzslupzojfuoztvzmmqvmlhgqxehojfowtrinbatjujaxekbcydldglkbxsqbbnrkhfdnpfbuaktupfftiljwpgglkjqunvithzlzpgikixqeuimmtbiskemplcvljqgvlzvnqxgedxqnznddkiujwhdefziydtquoudzxstpjjitmiimbjfgfjikkjycwgnpdxpeppsturjwkgnifinccvqzwlbmgpdaodzptyrjjkbqmgdrftfbwgimsmjpknuqtijrsnwvtytqqvookinzmkkkrkgwafohflvuedssukjgipgmypakhlckvizmqvycvbxhlljzejcaijqnfgobuhuiahtmxfzoplmmjfxtggwwxliplntkfuxjcnzcqsaagahbbneugiocexcfpszzomumfqpaiydssmihdoewahoswhlnpctjmkyufsvjlrflfiktndubnymenlmpyrhjxfdcq";
let s = "abc",
t = "ahbgdc";
let allPossibility = [];
function all(s, idx, arr, ans, empty = []) {
if (idx >= arr.length) {
if (empty.length === s.length) {
ans.push([...empty]);
}
return;
}
// if (empty.length > s.length) {
// return;
// }
empty.push(arr[idx]);
all(s, idx + 1, arr, ans, empty); // -----------------> Take an element
empty.pop();
all(s, idx + 1, arr, ans, empty); // -----------------> Not take element
}
all(s, 0, t.split(""), allPossibility);
console.log(allPossibility);