# LeetCode Queue Reconstruction by Height

LeetCode Queue Reconstruction by Height

Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers `(h, k)`, where `h` is the height of the person and `k` is the number of people in front of this person who have a height greater than or equal to `h`. Write an algorithm to reconstruct the queue.

Note:
The number of people is less than 1,100.

Example

```Input:
[[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]]

Output:
[[5,0], [7,0], [5,2], [6,1], [4,4], [7,1]]```

[7,0], [7,1], [6,1], [5,0], [5,2], [4,4]

1. [7,0]插入第0个位置，数组为[7,0]
2. [7,1]插入第1个位置，数组为[7,0], [7,1]
3. [6,1]插入第1个位置，数组为[7,0], [6,1], [7,1]
4. [5,0]插入第0个位置，数组为[5,0], [7,0], [6,1], [7,1]
5. [5,2]插入第2个位置，数组为[5,0], [7,0], [5,2], [6,1], [7,1]
6. [4,4]插入第4个位置，数组为[5,0], [7,0], [5,2], [6,1], [4,4], [7,1]

```bool comp(const pair<int, int>& p1, const pair<int, int>& p2) {
return p1.first > p2.first || (p1.first == p2.first&&p1.second < p2.second);
}

class Solution {
public:
vector<pair<int, int>> reconstructQueue(vector<pair<int, int>>& people) {
sort(people.begin(), people.end(), comp);
vector<pair<int, int>> ans;
for (int i = 0; i < people.size(); ++i) {
ans.insert(ans.begin() + people[i].second, people[i]);
}
return ans;
}
};
```