From 41603db88c020b22064ec84a4dec4a6f326201be Mon Sep 17 00:00:00 2001 From: deadmarshal Date: Mon, 2 Sep 2024 14:59:03 +0330 Subject: TWC285 --- challenge-285/deadmarshal/java/Ch1.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 challenge-285/deadmarshal/java/Ch1.java (limited to 'challenge-285/deadmarshal/java/Ch1.java') 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 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 ""; + } +} -- cgit