File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
src/1452-people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments