From e5b81df01cdc6588710edb4bf7a88de6cc8a8da8 Mon Sep 17 00:00:00 2001 From: Yang Date: Mon, 31 May 2021 16:43:45 -0400 Subject: [PATCH] =?UTF-8?q?Update=200452.=E7=94=A8=E6=9C=80=E5=B0=91?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E7=9A=84=E7=AE=AD=E5=BC=95=E7=88=86=E6=B0=94?= =?UTF-8?q?=E7=90=83.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Java code: - Fix an error in sorting (simplified as well) - Add checking for boundary condition --- problems/0452.用最少数量的箭引爆气球.md | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/problems/0452.用最少数量的箭引爆气球.md b/problems/0452.用最少数量的箭引爆气球.md index a8b55ca9..9b0cc925 100644 --- a/problems/0452.用最少数量的箭引爆气球.md +++ b/problems/0452.用最少数量的箭引爆气球.md @@ -142,16 +142,8 @@ Java: ```java class Solution { public int findMinArrowShots(int[][] points) { - Arrays.sort(points, new Comparator() { - @Override - public int compare(int[] o1, int[] o2) { - if (o1[0] != o2[0]) { - return Integer.compare(o1[0],o2[0]); - } else { - return Integer.compare(o1[0],o2[0]); - } - } - }); + if (points.length == 0) return 0; + Arrays.sort(points, (o1, o2) -> Integer.compare(o1[0], o2[0])); int count = 1; for (int i = 1; i < points.length; i++) {