From 3fc57152a3f1f4d9d93f4e7454059a3198cf5f0c Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Tue, 18 Nov 2025 07:11:03 +0000 Subject: [PATCH] [Sync Iteration] java/gotta-snatch-em-all/1 --- .../1/src/main/java/GottaSnatchEmAll.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 solutions/java/gotta-snatch-em-all/1/src/main/java/GottaSnatchEmAll.java diff --git a/solutions/java/gotta-snatch-em-all/1/src/main/java/GottaSnatchEmAll.java b/solutions/java/gotta-snatch-em-all/1/src/main/java/GottaSnatchEmAll.java new file mode 100644 index 0000000..d2a7b05 --- /dev/null +++ b/solutions/java/gotta-snatch-em-all/1/src/main/java/GottaSnatchEmAll.java @@ -0,0 +1,43 @@ +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +class GottaSnatchEmAll { + + static Set newCollection(List cards) { + return new HashSet<> (cards); + } + + static boolean addCard(String card, Set collection) { + return collection.add(card); + } + + static boolean canTrade(Set myCollection, Set theirCollection) { + Set myExtras = new HashSet<>(myCollection); + Set theirExtras = new HashSet<>(theirCollection); + + // Remove common cards + myExtras.removeAll(theirCollection); + theirExtras.removeAll(myCollection); + + return (myExtras.size() > 0) && (theirExtras.size() > 0); + + } + + static Set commonCards(List> collections) { + Set common = new HashSet<> (collections.get(0)); + + for(Set c : collections){ + common.retainAll(c); + } + return common; + } + + static Set allCards(List> collections) { + Set all = new HashSet<>(); + for(Set c : collections){ + all.addAll(c); + } + return all; + } +}