Open Tcdian opened 4 years ago
/**
* @param {number[][]} people
* @return {number[][]}
*/
var reconstructQueue = function(people) {
people.sort((a, b) => {
if (a[0] !== b[0]) {
return b[0] - a[0];
} else {
return a[1] - b[1];
}
});
let result = [];
for (let i = 0; i < people.length; i++) {
result.splice(people[i][1], 0, people[i]);
}
return result;
};
function reconstructQueue(people: number[][]): number[][] {
people.sort((a, b) => {
if (a[0] !== b[0]) {
return b[0] - a[0];
} else {
return a[1] - b[1];
}
});
let result: number[][] = [];
for (let i = 0; i < people.length; i++) {
result.splice(people[i][1], 0, people[i]);
}
return result;
};
406. Queue Reconstruction by Height
假设有打乱顺序的一群人站成一个队列。 每个人由一个整数对
(h, k)
表示,其中h
是这个人的身高,k
是排在这个人前面且身高大于或等于h
的人数。 编写一个算法来重建这个队列。Example
Note