Merge pull request #726 from GHumorBS/patch-3

Update 0406.根据身高重建队列.md
This commit is contained in:
程序员Carl
2021-09-09 11:08:24 +08:00
committed by GitHub

View File

@ -209,8 +209,13 @@ Python
```python
class Solution:
def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:
# 先按照h维度的身高顺序从高到低排序。确定第一个维度
# lambda返回的是一个元组当-x[0](维度h相同时再根据x[1]维度k从小到大排序
people.sort(key=lambda x: (-x[0], x[1]))
que = []
# 根据每个元素的第二个维度k贪心算法进行插入
# people已经排序过了同一高度时k值小的排前面。
for p in people:
que.insert(p[1], p)
return que