美文网首页
1282Group the People Given the G

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