From 432c2dc4440be0cd518d0ca1f87f546c77c8632c 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:16:21 +0000 Subject: [PATCH] [Sync Iteration] java/gotta-snatch-em-all/2 --- .../2/src/main/java/GottaSnatchEmAll.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 solutions/java/gotta-snatch-em-all/2/src/main/java/GottaSnatchEmAll.java diff --git a/solutions/java/gotta-snatch-em-all/2/src/main/java/GottaSnatchEmAll.java b/solutions/java/gotta-snatch-em-all/2/src/main/java/GottaSnatchEmAll.java new file mode 100644 index 0000000..f844284 --- /dev/null +++ b/solutions/java/gotta-snatch-em-all/2/src/main/java/GottaSnatchEmAll.java @@ -0,0 +1,38 @@ +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) { + boolean iHaveExtra = !myCollection.containsAll(theirCollection); + boolean theyHaveExtra = !theirCollection.containsAll(myCollection); + return iHaveExtra && theyHaveExtra; + + } + + 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; + } +}