[4,4], [7,1], [5,0], [6,1], [5,2]]
输出:
[[5,0], [7,0], [5,2], [6,1], [4,4], [7,1]]
思路
首先,大体上按照身高由大到小的顺序进行排序...于是,我们就需要进行两次排序,像箱子排序一样。所幸,python的sort函数是稳定的,于是我们就先将前方人数进行升序排序,再将身高进行降序排序。...class Solution:
def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:
# 先按照身高排序...,然后按照k升序排
# 最后进行index 插入
people.sort(key = lambda x: [-x[0], x[1]])
res = []...for p in people:
res.insert(p[1], p) # 基于后面的值作为index 插入到list中
return res