Skip to main content

406 - Queue Reconstruction by Height

Details

KeyValue
Linkhttps://leetcode.com/problems/queue-reconstruction-by-height/
LanguagePython 3
Runtime135 ms, faster than 66.19% of Python3 online submissions for Queue Reconstruction by Height
Memory Usage14.4 MB, less than 93.98% of Python3 online submissions for Queue Reconstruction by Height
DatastructuresList[List[int]]
AlgorithmsGreedy
ComplexityTime: O(N^2) Memory: O(N)

Procedure

  1. ...

Code

class Solution:
def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:
people.sort(key = lambda p: (-p[0], p[1]))
result = []
for p in people: result.insert(p[1], p)
return result