Skip to content

Commit 5084cf4

Browse files
Time: 26 ms (27.61%), Space: 13.4 MB (42.88%) - LeetHub
1 parent a35f167 commit 5084cf4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
vector<vector<int>> groupThePeople(vector<int>& groupSizes) {
4+
vector<vector<int>> res;
5+
vector<vector<int>> gz (groupSizes.size()+1);
6+
for(int i=0;i<groupSizes.size();i++){
7+
gz[groupSizes[i]].push_back(i);
8+
if(gz[groupSizes[i]].size()==groupSizes[i]){
9+
res.push_back({});
10+
swap(res.back(),gz[groupSizes[i]]);
11+
}
12+
}
13+
return res;
14+
}
15+
};

0 commit comments

Comments
 (0)