Merge pull request #156 from OlexanderD/patch-5
Changed code style according to new Java versions
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class SetCovering {
|
public class SetCovering {
|
||||||
|
public static void main(String... args) {
|
||||||
public static void main(String[] args) {
|
var statesNeeded = new HashSet<>(Arrays.asList("mt", "wa", "or", "id", "nv", "ut", "ca", "az"));
|
||||||
Set<String> statesNeeded = new HashSet(Arrays.asList("mt", "wa", "or", "id", "nv", "ut", "ca", "az"));
|
var stations = new LinkedHashMap<String, Set<String>>();
|
||||||
Map<String, Set<String>> stations = new LinkedHashMap<>();
|
|
||||||
|
|
||||||
stations.put("kone", new HashSet<>(Arrays.asList("id", "nv", "ut")));
|
stations.put("kone", new HashSet<>(Arrays.asList("id", "nv", "ut")));
|
||||||
stations.put("ktwo", new HashSet<>(Arrays.asList("wa", "id", "mt")));
|
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("kfour", new HashSet<>(Arrays.asList("nv", "ut")));
|
||||||
stations.put("kfive", new HashSet<>(Arrays.asList("ca", "az")));
|
stations.put("kfive", new HashSet<>(Arrays.asList("ca", "az")));
|
||||||
|
|
||||||
Set<String> finalStations = new HashSet<String>();
|
var finalStations = new HashSet<String>();
|
||||||
while (!statesNeeded.isEmpty()) {
|
while (!statesNeeded.isEmpty()) {
|
||||||
String bestStation = null;
|
String bestStation = null;
|
||||||
Set<String> statesCovered = new HashSet<>();
|
var statesCovered = new HashSet<String>();
|
||||||
|
|
||||||
for (Map.Entry<String, Set<String>> station : stations.entrySet()) {
|
for (var station : stations.entrySet()) {
|
||||||
Set<String> covered = new HashSet<>(statesNeeded);
|
var covered = new HashSet<>(statesNeeded);
|
||||||
covered.retainAll(station.getValue());
|
covered.retainAll(station.getValue());
|
||||||
|
|
||||||
if (covered.size() > statesCovered.size()) {
|
if (covered.size() > statesCovered.size()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user