Skip to content

Commit 1cd56c6

Browse files
committed
✨ people whose list of favorite companies is not a subset of anouther list
1 parent 49eb9db commit 1cd56c6

File tree

1 file changed

+40
-0
lines changed
  • src/1452-people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @param {string[][]} favoriteCompanies
3+
* @return {number[]}
4+
*/
5+
// HELP:
6+
var peopleIndexes = function (favoriteCompanies) {
7+
let res = [];
8+
let len = favoriteCompanies.length;
9+
10+
for (let i = 0; i < len; i++) {
11+
let cur = favoriteCompanies[i];
12+
let flag = true;
13+
14+
// 当前的能不能加入结果,只要它不是任何人的子集
15+
for (let j = 0; j < len; j++) {
16+
let hash = new Set(cur);
17+
let next = favoriteCompanies[j];
18+
if (i == j || cur.length > next.length) {
19+
continue;
20+
}
21+
22+
for (let k = 0; k < next.length; k++) {
23+
if (hash.has(next[k])) {
24+
hash.delete(next[k]);
25+
}
26+
}
27+
28+
// 删完了,你是我的子集,不能加
29+
if (hash.size === 0) {
30+
flag = false;
31+
break;
32+
}
33+
}
34+
35+
if (flag) {
36+
res.push(i);
37+
}
38+
}
39+
return res;
40+
};

0 commit comments

Comments
 (0)