406. Queue Reconstruction by Height

https://leetcode.com/problems/queue-reconstruction-by-height/

这么理解先插高的,这样当我们使用insert(pos,number) 我们能保证pos之前的都是比number大的数

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

Last updated

Was this helpful?