aboutsummaryrefslogtreecommitdiff
path: root/challenge-285/deadmarshal/java/Ch1.java
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-285/deadmarshal/java/Ch1.java')
-rw-r--r--challenge-285/deadmarshal/java/Ch1.java23
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-285/deadmarshal/java/Ch1.java b/challenge-285/deadmarshal/java/Ch1.java
new file mode 100644
index 0000000000..8b8f8229f4
--- /dev/null
+++ b/challenge-285/deadmarshal/java/Ch1.java
@@ -0,0 +1,23 @@
+import java.util.HashMap;
+import java.util.Map;
+
+public class Ch1 {
+ public static void main(String[] args) {
+ String[][] arr1 = {{"B", "C"}, {"D", "B"}, {"C", "A"}};
+ String[][] arr2 = {{"A", "Z"}};
+ System.out.println(no_connection(arr1));
+ System.out.println(no_connection(arr2));
+ }
+
+ private static String no_connection(String[][] arr) {
+ Map<String, Integer> destinations = new HashMap<>(),
+ sources = new HashMap<>();
+ for (String[] a : arr) {
+ sources.put(a[0], 1);
+ destinations.put(a[1], 1);
+ }
+ for (String d : destinations.keySet())
+ if (!sources.containsKey(d)) return d;
+ return "";
+ }
+}