From 91975f0f94bc6c7cbf770d54860e1e5e1417782c Mon Sep 17 00:00:00 2001 From: Adarsh Kumar <58614055+i-adarsh@users.noreply.github.com> Date: Tue, 4 Mar 2025 09:42:45 +0530 Subject: [PATCH] Changing comparator to lambda expression Changing comparator to lambda expression, as it is easy to code in interviews --- KruskalsAlgorithm.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/KruskalsAlgorithm.java b/KruskalsAlgorithm.java index 9c30339..53319e1 100644 --- a/KruskalsAlgorithm.java +++ b/KruskalsAlgorithm.java @@ -2,11 +2,7 @@ class Solution { static int spanningTree(int V, int E, List> adj) { // Code Here. //(u, v, weight) - PriorityQueue pq = new PriorityQueue<>(new Comparator<>(){ - public int compare(int pair1[], int pair2[]){ - return pair1[2] - pair2[2]; - } - }); + PriorityQueue pq = new PriorityQueue<>((a, b) -> a[2] - b[2]); // insert edges in pq for(int i=0;i