406. Queue Reconstruction by Height

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

solution

  • 两个维度h和k,看到这种题目要想如何确定一个维度,然后再按照另一个维度重新排列

class Solution:
    def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:
        people.sort(key=lambda x: (-x[0], x[1]))      # 高度升序, k降序
        
        que = []
        for p in people:
            que.insert(p[1], p)
        return que

时间复杂度:O() 空间复杂度:O()

Last updated