Update 0406.根据身高重建队列.md

补充一下python注释,更好理解python语法
This commit is contained in:
Asterisk
2021-09-07 17:00:25 +08:00
committed by GitHub
parent b1f8c998a1
commit 4d91c78e1e

View File

@ -209,8 +209,13 @@ Python
```python ```python
class Solution: class Solution:
def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]: 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])) people.sort(key=lambda x: (-x[0], x[1]))
que = [] que = []
# 根据每个元素的第二个维度k贪心算法进行插入
# people已经排序过了同一高度时k值小的排前面。
for p in people: for p in people:
que.insert(p[1], p) que.insert(p[1], p)
return que return que