406.高さC ++ソリューションによるキューの再構築



406 Queue Reconstruction Height C Solution



まず、人は最初のアイテムの降順で並べ替えられます(最初のアイテムは2番目のアイテムと同じです)。次に、それを再挿入します。
注意すべき点の1つは、ソートの比較ルールが書き直されていることです。クラスに書き込むには、関数の前にstaticを追加する必要があります。

class Solution { public: static bool cmp(pair a, pair b) { if (a.first == b.first) return a.second b.first } vector reconstructQueue(vector& people) { vector res if (people.empty()) return res sort(people.begin(), people.end(),cmp) res.push_back(people[0]) for (int i = 1 i