Skip to content

Commit

Permalink
Create 1452.People-Whose-List-of-Favorite-Companies-Is-Not-a-Subset-o…
Browse files Browse the repository at this point in the history
…f-Another-List_v2.cpp
  • Loading branch information
wisdompeak authored Nov 21, 2020
1 parent a803651 commit a32d349
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Solution {
public:
vector<int> peopleIndexes(vector<vector<string>>& favoriteCompanies)
{
int n = favoriteCompanies.size();
unordered_map<string,bitset<100>>c2p;
for (int i=0; i<n; i++)
for (int j=0; j<favoriteCompanies[i].size(); j++)
c2p[favoriteCompanies[i][j]][i] = 1;

vector<int>rets;
bitset<100>state;
for (int i=0; i<n; i++)
{
state.set();

for (string c: favoriteCompanies[i])
{
state = state & c2p[c];
}
if (state.count()==1)
rets.push_back(i);
}
return rets;
}
};

0 comments on commit a32d349

Please sign in to comment.