From 878e26217dca2b7de7f36030217b117c891ce758 Mon Sep 17 00:00:00 2001 From: Lu Zhang Date: Wed, 30 Oct 2019 14:32:32 -0700 Subject: [PATCH] Update SetCovering.java (#120) The statesNeeded and finalStations set should be updated after the for loop which finds the bestStation. --- .../java/01_set_covering/src/SetCovering.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/08_greedy_algorithms/java/01_set_covering/src/SetCovering.java b/08_greedy_algorithms/java/01_set_covering/src/SetCovering.java index 86f0791..9afd2c8 100644 --- a/08_greedy_algorithms/java/01_set_covering/src/SetCovering.java +++ b/08_greedy_algorithms/java/01_set_covering/src/SetCovering.java @@ -25,13 +25,13 @@ public class SetCovering { bestStation = station.getKey(); statesCovered = covered; } - statesNeeded.removeIf(statesCovered::contains); + } + statesNeeded.removeIf(statesCovered::contains); - if (bestStation != null) { - finalStations.add(bestStation); - } + if (bestStation != null) { + finalStations.add(bestStation); } } System.out.println(finalStations); // [ktwo, kone, kthree, kfive] } -} \ No newline at end of file +}