Skip to content

Commit a29af47

Browse files
committed
https://leetcode.cn/problems/queue-reconstruction-by-height/
1 parent 399d2e4 commit a29af47

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ leetcode 测试
1010

1111
##### 包含的内容如下
1212

13+
https://leetcode.cn/problems/queue-reconstruction-by-height/
14+
1315
https://leetcode.cn/problems/design-file-system/
1416

1517
https://leetcode.cn/problems/find-duplicate-file-in-system/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default function reconstructQueue(people: number[][]): number[][] {
2+
const queue: number[][] = [];
3+
people.sort((a, b) => {
4+
if (b[0] !== a[0]) {
5+
return b[0] - a[0];
6+
} else {
7+
return a[1] - b[1];
8+
}
9+
});
10+
11+
for (let i = 0; i < people.length; i++) {
12+
queue.splice(people[i][1], 0, people[i]);
13+
}
14+
return queue;
15+
}

0 commit comments

Comments
 (0)