1282Group the People Given the Group Size They Belong To

class Solution {
public:
    vector> groupThePeople(vector& groupSizes) {
        vector> res;
        map> counts;
        for (int i = 0, len = groupSizes.size(); i < len; i++) {
            counts[groupSizes.at(i)].push_back(i);
        }
        map> ::iterator mapIter = counts.begin();
        for (; mapIter != counts.end(); mapIter++) {
            int key = mapIter -> first;
            vector ids = mapIter -> second;
            vector ::iterator vecIter = ids.begin();
            while(vecIter != ids.end()) {
                vector idsSub(vecIter, vecIter + key);
                vecIter += key;
                res.push_back(idsSub);
            }
        }
        return res;
    }
};

你可能感兴趣的:(1282Group the People Given the Group Size They Belong To)