From 04ccd8808b9e68478b56c6af0c9855695b5378d3 Mon Sep 17 00:00:00 2001 From: kriseattle Date: Mon, 9 Jun 2025 11:17:34 -0700 Subject: [PATCH 1/3] Implimented DuplicatedRemover --- src/DuplicateRemover.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/DuplicateRemover.java b/src/DuplicateRemover.java index 8d70003..ecf1237 100644 --- a/src/DuplicateRemover.java +++ b/src/DuplicateRemover.java @@ -1,4 +1,7 @@ +import java.util.ArrayList; import java.util.List; +import java.util.Set; +import java.util.TreeSet; /** * The DuplicateRemover class provides a method to remove duplicate words @@ -15,7 +18,17 @@ public class DuplicateRemover { */ public static List sortAndRemoveDuplicates(String[] words) { // TODO - return null; + Set unique = new TreeSet<>(); + for (String word : words) { + unique.add(word); + } + + List wordList = new ArrayList<>(); + for (String word : unique) { + wordList.add(word); + } + + return wordList; } public static void main(String[] args) { From bcfa729766f5d580c73d672fae1466e6d9ae13a4 Mon Sep 17 00:00:00 2001 From: kriseattle Date: Mon, 9 Jun 2025 11:25:31 -0700 Subject: [PATCH 2/3] Added code for UniqueCharacterChecker --- src/UniqueCharacterChecker.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/UniqueCharacterChecker.java b/src/UniqueCharacterChecker.java index 554ffc4..668758a 100644 --- a/src/UniqueCharacterChecker.java +++ b/src/UniqueCharacterChecker.java @@ -1,3 +1,6 @@ +import java.util.HashSet; +import java.util.Set; + /** * The UniqueCharacterChecker class provides a method to check if all characters * in a given word are unique. @@ -14,7 +17,14 @@ public static boolean hasUniqueCharacters(String word) { // TODO: implement this! // Requirement: This must run in O(n) time, where n is the number of characters in the word // Hint: Stuck? Consider looking up "charAt" and seeing how it can help you - return false; + + Set charSet = new HashSet<>(); + + for (char c : word.toCharArray()) { + charSet.add(c); + } + + return charSet.size() == word.length(); } public static void main(String[] args) { From 1f2577c73297ac85bc29559f539a5a3ca4407557 Mon Sep 17 00:00:00 2001 From: kriseattle Date: Mon, 9 Jun 2025 11:34:31 -0700 Subject: [PATCH 3/3] CommonElementsFinder method --- src/CommonElementsFinder.java | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/CommonElementsFinder.java b/src/CommonElementsFinder.java index fb88a4b..7d98c9b 100644 --- a/src/CommonElementsFinder.java +++ b/src/CommonElementsFinder.java @@ -1,4 +1,5 @@ import java.util.Set; +import java.util.TreeSet; /** * The CommonElementsFinder class provides a method for finding common elements @@ -15,7 +16,26 @@ public class CommonElementsFinder { */ public static Set findCommonElements(int[] array1, int[] array2) { // TODO - return null; + + Set set1 = new TreeSet<>(); + for (int num : array1) { + set1.add(num); + } + + + Set set2 = new TreeSet<>(); + for (int num : array2) { + set2.add(num); + } + + Set commonNumSet = new TreeSet<>(); + for (int num : set1) { + if (set2.contains(num)) { + commonNumSet.add(num); + } + } + + return commonNumSet; }