https://leetcode.com/problems/queue-reconstruction-by-height
My answer / NAC
太菜了就不贴了
Best answer
/**
* @param {number[][]} people
* @return {number[][]}
*/
var reconstructQueue = function(people) {
people=people.sort((a,b)=>a[0]==b[0]?a[1]-b[1]:b[0]-a[0])
console.log(people)
res=[];
people.forEach(o=>{
res.splice(o[1], 0, o);
})
return res;
};
/* Your input:
* [[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]]
* Sorted:
* [ [ 7, 0 ], [ 7, 1 ], [ 6, 1 ], [ 5, 0 ], [ 5, 2 ], [ 4, 4 ] ]
* Output:
* [[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]]
- 思考好,排序的方法很重要!先按从大到小排,再按前面人头数的从小到大排
Recap
这里主要是考察逻辑,我的逻辑还要加油!







网友评论