解题思路:用哈希表存储某个公司出现过的清单,对每一个清单求每个每个公司清单的并集,如果并集不为空说明这个清单被包含在其他清单中
代码如下:
class Solution:
def peopleIndexes(self, favoriteCompanies: List[List[str]]) -> List[int]:
tabel = {}
size = len(favoriteCompanies)
length = []
for i in range(size):
length.append(len(favoriteCompanies[i]))
for x in favoriteCompanies[i]:
if x not in tabel:
tabel[x] = [i]
else:
tabel[x].append(i)
import numpy as np
index = list(np.argsort(np.array(length)))
res = []
for i in range(size):
if i == size -1:
tmp = []
j = i - 1
while(j >= 0 and length[index[j]] == length[index[i]]):
tmp.append(index[j])
j -= 1
tmp = set(tmp)
else:
tmp = set(index[i+1:])
for x in favoriteCompanies[index[i]]:
tmp = tmp & set(tabel[x])
if len(tmp) == 0:
res.append(int(index[i]))
res = sorted(res)
return res