题目描述
https://leetcode-cn.com/problems/queue-reconstruction-by-height/
思路题解
先进行排序,对第一位降序,第二维升序。
再对其进行模拟,因为长得高的看不见长得矮的,所以先确定高的,同样的身高里面先确定前面需要的人数少的。
class Solution:
def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:
people.sort(key=lambda x:(-x[0],x[1]))
ans=[]
for p in people:
ans.insert(p[1],p)
return ans