From 7beb711f0df90795c0f4df537b8aaab897d5e98c Mon Sep 17 00:00:00 2001 From: fusunx <1102654482@qq.com> Date: Wed, 9 Jun 2021 08:22:29 +0800 Subject: [PATCH 1/2] =?UTF-8?q?0406.=E6=A0=B9=E6=8D=AE=E8=BA=AB=E9=AB=98?= =?UTF-8?q?=E4=BD=93=E9=87=8D=E9=87=8D=E5=BB=BA=E9=98=9F=E5=88=97=20Javasc?= =?UTF-8?q?ript?= 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 eec9680b..9aca5b94 100644 --- a/problems/0406.根据身高重建队列.md +++ b/problems/0406.根据身高重建队列.md @@ -226,7 +226,25 @@ class Solution: Go: +Javascript: +```Javascript +var reconstructQueue = function(people) { + let queue = [] + people.sort((a, b ) => { + if(b[0] !== a[0]) { + return b[0] - a[0] + } else { + return a[1] - b[1] + } + + }) + for(let i = 0; i < people.length; i++) { + queue.splice(people[i][1], 0, people[i]) + } + return queue +}; +``` ----------------------- From f19cc3ddd4c4fb347761678d94e308131ff520b9 Mon Sep 17 00:00:00 2001 From: fusunx <1102654482@qq.com> Date: Thu, 10 Jun 2021 08:14:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?0452.=E7=94=A8=E6=9C=80=E5=B0=91=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E7=9A=84=E7=AE=AD=E5=BC=95=E7=88=86=E6=B0=94=E7=90=83?= =?UTF-8?q?=20Javascript?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0452.用最少数量的箭引爆气球.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/problems/0452.用最少数量的箭引爆气球.md b/problems/0452.用最少数量的箭引爆气球.md index 9b0cc925..bb3ebbdc 100644 --- a/problems/0452.用最少数量的箭引爆气球.md +++ b/problems/0452.用最少数量的箭引爆气球.md @@ -175,7 +175,24 @@ class Solution: Go: +Javascript: +```Javascript +var findMinArrowShots = function(points) { + points.sort((a, b) => { + return a[0] - b[0] + }) + let result = 1 + for(let i = 1; i < points.length; i++) { + if(points[i][0] > points[i - 1][1]) { + result++ + } else { + points[i][1] = Math.min(points[i - 1][1], points[i][1]) + } + } + return result +}; +``` -----------------------