forked from wisdompeak/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create 1452.People-Whose-List-of-Favorite-Companies-Is-Not-a-Subset-o…
…f-Another-List_v2.cpp
- Loading branch information
1 parent
a803651
commit a32d349
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
...-List/1452.People-Whose-List-of-Favorite-Companies-Is-Not-a-Subset-of-Another-List_v2.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |