Queue Reconstruction by Height
https://www.lintcode.com/problem/queue-reconstruction-by-height/description
class Solution:
"""
@param people: a random list of people
@return: the queue that be reconstructed
"""
def reconstructQueue(self, people):
# write your code here
people.sort(key= lambda x: (-x[0],x[1]))
res = []
for p in people:
res.insert(p[1],p)
return res
在python里sort comparator可以很容易用lambda表示出来。
类似于如果node是三维的如下
array.sort(key=lambda x: (x[0],x[1],x[2]))
Last updated
Was this helpful?