-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1282.用户分组.cpp
45 lines (43 loc) · 1.14 KB
/
1282.用户分组.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* @lc app=leetcode.cn id=1282 lang=cpp
*
* [1282] 用户分组
*/
#include <iostream>
#include <vector>
#include <map>
using namespace std;
// @lc code=start
class Solution {
public:
vector<vector<int>> groupThePeople(vector<int>& groupSizes) {
map<int, vector<int>> m;
for(int i = 0; i < groupSizes.size();i++){
int size = groupSizes[i];
auto it = m.find(size);
if(it != m.end()){
m[size].push_back(i);
}else{
m.insert(pair<int, vector<int>>(size, {i}));
}
}
vector<vector<int>> vv;
for (auto it = m.begin(); it != m.end(); ++it)
{
int key = it->first;
vector<int>& value = m[key];
vector<int> v;
int count = 0;
while(count < value.size()){
for(int i = 0; i<key; i++){
v.push_back(value[count+i]);
}
vv.push_back(v);
v.clear();
count += key;
}
}
return vv;
}
};
// @lc code=end