From 175b71d21fc5e3bdddc21e5dafe8a73980d79016 Mon Sep 17 00:00:00 2001 From: Steve2020 <841532108@qq.com> Date: Sun, 10 Apr 2022 21:59:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=880406.=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E8=BA=AB=E9=AB=98=E9=87=8D=E5=BB=BA=E9=98=9F=E5=88=97?= =?UTF-8?q?.md=EF=BC=89=EF=BC=9A=E5=A2=9E=E5=8A=A0typescript=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0406.根据身高重建队列.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/problems/0406.根据身高重建队列.md b/problems/0406.根据身高重建队列.md index b2354d09..ecb05301 100644 --- a/problems/0406.根据身高重建队列.md +++ b/problems/0406.根据身高重建队列.md @@ -290,6 +290,24 @@ var reconstructQueue = function(people) { }; ``` +### TypeScript + +```typescript +function reconstructQueue(people: number[][]): number[][] { + people.sort((a, b) => { + if (a[0] === b[0]) return a[1] - b[1]; + return b[0] - a[0]; + }); + const resArr: number[][] = []; + for (let i = 0, length = people.length; i < length; i++) { + resArr.splice(people[i][1], 0, people[i]); + } + return resArr; +}; +``` + + + -----------------------