You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
16
+
17
+
Note:
18
+
The number of people is less than 1,100.
19
+
20
+
21
+
Example
22
+
23
+
Input:
24
+
[[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]]
25
+
26
+
Output:
27
+
[[5,0], [7,0], [5,2], [6,1], [4,4], [7,1]]
28
+
```
29
+
30
+
## 解题方案
31
+
32
+
> 思路 1
33
+
******- 时间复杂度: O(NlgN)******- 空间复杂度: O(1)******
11
34
12
-
思路:
13
35
People are only counting (in their k-value) taller or equal-height others standing in front of them.
14
36
So a smallest person is completely irrelevant for all taller ones. And of all smallest people,
15
37
the one standing most in the back is even completely irrelevant for everybody else. Nobody is counting that person.
@@ -26,18 +48,20 @@ Sorting the people from the first-tallest to the last-smallest, and inserting th
0 commit comments