Skip to content

Commit fa07a98

Browse files
committed
update: 406
1 parent 6dd1267 commit fa07a98

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
150150
| 384 | [Shuffle an Array](https://leetcode.com/problems/shuffle-an-array/) | [JavaScript](./src/shuffle-an-array/res.js) | Medium |
151151
| 395 | [Longest Substring with At Least K Repeating Characters](https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters/) | [JavaScript](./src/longest-substring-with-at-least-k-repeating-characters/res.js) | Medium |
152152
| 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves/) | [JavaScript](./src/sum-of-left-leaves/res.js) | Easy |
153+
| 406 | [queue-reconstruction-by-height](https://leetcode.com/problems/queue-reconstruction-by-height/) | [TypeScript](./src/queue-reconstruction-by-height/res.ts) | Medium |
153154
| 413 | [Arithmetic Slices](https://leetcode.com/problems/arithmetic-slices/) | [JavaScript](./src/arithmetic-slices/res.js) | Medium |
154155
| 416 | [Partition Equal Subset Sum](https://leetcode.com/problems/partition-equal-subset-sum/) | [JavaScript](./src/partition-equal-subset-sum/res.js) | Medium |
155156
| 424 | [Longest Repeating Character Replacement](https://leetcode.com/problems/longest-repeating-character-replacement/) | [JavaScript](./src/longest-repeating-character-replacement/res.js) | Medium |
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* 先按照高度降序排列,再按照人数升序排列
3+
* 然后依次插入,每次插入时,之前插入过的元素都会比当前元素要高
4+
* @param people
5+
*/
6+
function reconstructQueue(people: number[][]): number[][] {
7+
people.sort((a, b) => (b[0] - a[0]) || (a[1] - b[1]));
8+
9+
let result: number[][] = [];
10+
people.forEach(item => {
11+
if (item[1] >= result.length) {
12+
result.push(item);
13+
} else {
14+
result = [...result.slice(0, item[1]), item, ...result.slice(item[1])];
15+
}
16+
});
17+
18+
return result;
19+
};

0 commit comments

Comments
 (0)