美文网首页
406. Queue Reconstruction by Hei

406. Queue Reconstruction by Hei

作者: 我是你的果果呀 | 来源:发表于2016-12-06 07:45 被阅读0次

Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers(h, k), wherehis the height of the person andkis the number of people in front of this person who have a height greater than or equal toh. Write an algorithm to reconstruct the queue.

Note:
The number of people is less than 1,100.
Example
Input:  [[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]]
Output:  [[5,0], [7,0], [5,2], [6,1], [4,4], [7,1]]

h 为身高, k为排在他前面的身高大于等于他身高的人数。

step1: 身高降序排列, 如果身高一致,很显然k要升序排列。

list to array 时候要在参数里new 一个int的数组! 这个输入参数的格式作为模板传进去, 等返回来时,已经装满了数据。 想想满满的幸福感。 

相关文章

网友评论

      本文标题:406. Queue Reconstruction by Hei

      本文链接:https://www.haomeiwen.com/subject/qsglmttx.html