refactor:Simplified lambda expressions for PriorityQueue in heap.md and heap.java (#379)

This commit is contained in:
t8g 2023-02-22 19:35:49 +08:00 committed by GitHub
parent a2b74943a2
commit f2d2cca5f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -28,7 +28,7 @@ public class heap {
// 初始化小顶堆
Queue<Integer> minHeap = new PriorityQueue<>();
// 初始化大顶堆使用 lambda 表达式修改 Comparator 即可
Queue<Integer> maxHeap = new PriorityQueue<>((a, b) -> { return b - a; });
Queue<Integer> maxHeap = new PriorityQueue<>((a, b) -> b - a);
System.out.println("\n以下测试样例为大顶堆");

View File

@ -52,7 +52,7 @@ comments: true
// 初始化小顶堆
Queue<Integer> minHeap = new PriorityQueue<>();
// 初始化大顶堆(使用 lambda 表达式修改 Comparator 即可)
Queue<Integer> maxHeap = new PriorityQueue<>((a, b) -> { return b - a; });
Queue<Integer> maxHeap = new PriorityQueue<>((a, b) -> b - a);
/* 元素入堆 */
maxHeap.add(1);