From f2d2cca5f1fe657423f7872bdf37ab7615308d50 Mon Sep 17 00:00:00 2001 From: t8g <89574863+4yDX3906@users.noreply.github.com> Date: Wed, 22 Feb 2023 19:35:49 +0800 Subject: [PATCH] refactor:Simplified lambda expressions for PriorityQueue in heap.md and heap.java (#379) --- codes/java/chapter_heap/heap.java | 2 +- docs/chapter_heap/heap.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/codes/java/chapter_heap/heap.java b/codes/java/chapter_heap/heap.java index 35ca6af0..1ac63527 100644 --- a/codes/java/chapter_heap/heap.java +++ b/codes/java/chapter_heap/heap.java @@ -28,7 +28,7 @@ public class heap { // 初始化小顶堆 Queue minHeap = new PriorityQueue<>(); // 初始化大顶堆(使用 lambda 表达式修改 Comparator 即可) - Queue maxHeap = new PriorityQueue<>((a, b) -> { return b - a; }); + Queue maxHeap = new PriorityQueue<>((a, b) -> b - a); System.out.println("\n以下测试样例为大顶堆"); diff --git a/docs/chapter_heap/heap.md b/docs/chapter_heap/heap.md index ea805e3a..76ffe15e 100644 --- a/docs/chapter_heap/heap.md +++ b/docs/chapter_heap/heap.md @@ -52,7 +52,7 @@ comments: true // 初始化小顶堆 Queue minHeap = new PriorityQueue<>(); // 初始化大顶堆(使用 lambda 表达式修改 Comparator 即可) - Queue maxHeap = new PriorityQueue<>((a, b) -> { return b - a; }); + Queue maxHeap = new PriorityQueue<>((a, b) -> b - a); /* 元素入堆 */ maxHeap.add(1);