Changed code style according to new Java versions
Changed long and ugly type declarations with "var" keyword (Java 10). Also fixed warning about raw usage of HashSet without type specification.
This commit is contained in:
committed by
GitHub
parent
d8da439590
commit
52a5a7cc24
@@ -1,10 +1,9 @@
|
||||
import java.util.*;
|
||||
|
||||
public class SetCovering {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Set<String> statesNeeded = new HashSet(Arrays.asList("mt", "wa", "or", "id", "nv", "ut", "ca", "az"));
|
||||
Map<String, Set<String>> 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<String, Set<String>>();
|
||||
|
||||
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<String> finalStations = new HashSet<String>();
|
||||
var finalStations = new HashSet<String>();
|
||||
while (!statesNeeded.isEmpty()) {
|
||||
String bestStation = null;
|
||||
Set<String> statesCovered = new HashSet<>();
|
||||
var statesCovered = new HashSet<String>();
|
||||
|
||||
for (Map.Entry<String, Set<String>> station : stations.entrySet()) {
|
||||
Set<String> covered = new HashSet<>(statesNeeded);
|
||||
for (var station : stations.entrySet()) {
|
||||
var covered = new HashSet<>(statesNeeded);
|
||||
covered.retainAll(station.getValue());
|
||||
|
||||
if (covered.size() > statesCovered.size()) {
|
||||
|
||||
Reference in New Issue
Block a user