1282Group the People Given the G
作者:
是嘤嘤嘤呀 | 来源:发表于
2020-03-27 17:48 被阅读0次class Solution {
public:
vector<vector<int>> groupThePeople(vector<int>& groupSizes) {
vector<vector<int>> res;
map<int, vector<int>> counts;
for (int i = 0, len = groupSizes.size(); i < len; i++) {
counts[groupSizes.at(i)].push_back(i);
}
map<int, vector<int>> ::iterator mapIter = counts.begin();
for (; mapIter != counts.end(); mapIter++) {
int key = mapIter -> first;
vector<int> ids = mapIter -> second;
vector<int> ::iterator vecIter = ids.begin();
while(vecIter != ids.end()) {
vector<int> idsSub(vecIter, vecIter + key);
vecIter += key;
res.push_back(idsSub);
}
}
return res;
}
};
本文标题:1282Group the People Given the G
本文链接:https://www.haomeiwen.com/subject/iokruhtx.html
网友评论