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 9afd2c8..c9cbff6 100644 --- a/08_greedy_algorithms/java/01_set_covering/src/SetCovering.java +++ b/08_greedy_algorithms/java/01_set_covering/src/SetCovering.java @@ -1,10 +1,9 @@ import java.util.*; public class SetCovering { - - public static void main(String[] args) { - Set statesNeeded = new HashSet(Arrays.asList("mt", "wa", "or", "id", "nv", "ut", "ca", "az")); - Map> stations = new LinkedHashMap<>(); + public static void main(String... args) { + var statesNeeded = new HashSet<>(Arrays.asList("mt", "wa", "or", "id", "nv", "ut", "ca", "az")); + var stations = new LinkedHashMap>(); stations.put("kone", new HashSet<>(Arrays.asList("id", "nv", "ut"))); stations.put("ktwo", new HashSet<>(Arrays.asList("wa", "id", "mt"))); @@ -12,13 +11,13 @@ public class SetCovering { stations.put("kfour", new HashSet<>(Arrays.asList("nv", "ut"))); stations.put("kfive", new HashSet<>(Arrays.asList("ca", "az"))); - Set finalStations = new HashSet(); + var finalStations = new HashSet(); while (!statesNeeded.isEmpty()) { String bestStation = null; - Set statesCovered = new HashSet<>(); + var statesCovered = new HashSet(); - for (Map.Entry> station : stations.entrySet()) { - Set covered = new HashSet<>(statesNeeded); + for (var station : stations.entrySet()) { + var covered = new HashSet<>(statesNeeded); covered.retainAll(station.getValue()); if (covered.size() > statesCovered.size()) {