-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__M__999__word-subsets.js
58 lines (54 loc) · 1.52 KB
/
__M__999__word-subsets.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
49
50
51
52
53
54
55
56
57
58
// https://leetcode.com/problems/word-subsets/
const c = console.log.bind(console);
let p = "abcde";
// c(p.indexOf('b'))
// c(p.slice(0, 2) + p.slice(3))
// c(p)
var wordSubsets = function(words1, words2) {
words2 = [...new Set(words2)];
return words1.filter((item) => {
let tempItem = item;
let bool = "";
try {
words2.forEach((i) => {
tempItem = item;
i.split("").forEach((j) => {
if (!tempItem.includes(j)) {
bool = false;
throw "fuck";
} else {
tempItem = tempItem.slice(0, tempItem.indexOf(j)) + tempItem.slice(parseInt(tempItem.indexOf(j)) + 1)
// c(tempItem)
bool = true;
}
});
// if (!item.includes(i)) {
// bool = false;
// throw "fuck";
// } else {
// bool = true;
// }
});
} catch (err) {
// c(err);
} finally {
if (bool) {
return item;
}
}
// c(item)
});
};
c(
wordSubsets(["amazon", "apple", "facebook", "google", "leetcode"], ["e", "o"])
);
c(
wordSubsets(
["amazon", "apple", "facebook", "google", "leetcode"], ["lo", "eo"]
)
);
c(
wordSubsets(
["amazon", "apple", "facebook", "google", "leetcode"], ["e", "oo"]
)
);