406. Queue Reconstruction by Height
https://leetcode.com/problems/queue-reconstruction-by-height/
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]]Thoughts
Code
class Solution:
def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:
people, res = sorted(people, reverse=True, key=lambda x: (x[0], -x[1])), []
for p in people:
res.insert(p[1], p)
return resAnalysis
Last updated