From 01f14ae547f6af6a68babeaa4bb562ee14253309 Mon Sep 17 00:00:00 2001 From: daniel1n <54945782+daniel1n@users.noreply.github.com> Date: Sun, 18 Jul 2021 13:35:20 +0800 Subject: [PATCH] =?UTF-8?q?Update=200406.=E6=A0=B9=E6=8D=AE=E8=BA=AB?= =?UTF-8?q?=E9=AB=98=E9=87=8D=E5=BB=BA=E9=98=9F=E5=88=97.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新Java:使用lambda --- problems/0406.根据身高重建队列.md | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/problems/0406.根据身高重建队列.md b/problems/0406.根据身高重建队列.md index 2b447da4..a5f66a5d 100644 --- a/problems/0406.根据身高重建队列.md +++ b/problems/0406.根据身高重建队列.md @@ -188,15 +188,10 @@ Java: ```java class Solution { public int[][] reconstructQueue(int[][] people) { - Arrays.sort(people, new Comparator() { - @Override - public int compare(int[] o1, int[] o2) { - if (o1[0] != o2[0]) { - return Integer.compare(o2[0],o1[0]); - } else { - return Integer.compare(o1[1],o2[1]); - } - } + // 身高从大到小排(身高相同k小的站前面) + Arrays.sort(people, (a, b) -> { + if (a[0] == b[0]) return a[1] - b[1]; + return b[0] - a[0]; }); LinkedList que = new LinkedList<>();