From 73b88b5395e1d016f6ebf7ce18aec60e1ba466df Mon Sep 17 00:00:00 2001 From: Akai <161771111+Akaiokaa@users.noreply.github.com> Date: Mon, 9 Jun 2025 21:50:45 -0700 Subject: [PATCH 1/3] Implemented sortAndRemoveDuplicates method --- src/DuplicateRemover.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/DuplicateRemover.java b/src/DuplicateRemover.java index 8d70003..4984ea6 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 @@ -14,8 +17,16 @@ public class DuplicateRemover { * @return a sorted List containing unique words from the input array */ 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 b77af13969ce4ca84152b2b09cfec1b68a5f19b1 Mon Sep 17 00:00:00 2001 From: Akai <161771111+Akaiokaa@users.noreply.github.com> Date: Tue, 10 Jun 2025 00:25:35 -0700 Subject: [PATCH 2/3] Implemented the findCommonElements method --- src/CommonElementsFinder.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/CommonElementsFinder.java b/src/CommonElementsFinder.java index fb88a4b..32a6087 100644 --- a/src/CommonElementsFinder.java +++ b/src/CommonElementsFinder.java @@ -1,3 +1,4 @@ +import java.util.HashSet; import java.util.Set; /** @@ -15,7 +16,21 @@ public class CommonElementsFinder { */ public static Set findCommonElements(int[] array1, int[] array2) { // TODO - return null; + Set hash1 = new HashSet<>(); + for (Integer integer : array1) { + hash1.add(integer); + } + Set hash2 = new HashSet<>(); + for (Integer integer : array2) { + hash2.add(integer); + } + Set commonHash = new HashSet<>(); + for (Integer integer : hash2) { + if (hash1.contains(integer)) { + commonHash.add(integer); + } + } + return commonHash; } From cd504328ad98c0b6aa16bf80369e081f08bdfa68 Mon Sep 17 00:00:00 2001 From: Akai <161771111+Akaiokaa@users.noreply.github.com> Date: Tue, 10 Jun 2025 01:06:39 -0700 Subject: [PATCH 3/3] Implemented haaUniqueCharacters method --- src/UniqueCharacterChecker.java | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/UniqueCharacterChecker.java b/src/UniqueCharacterChecker.java index 554ffc4..187fb5a 100644 --- a/src/UniqueCharacterChecker.java +++ b/src/UniqueCharacterChecker.java @@ -1,3 +1,7 @@ +import java.util.HashSet; +import java.util.Set; +import java.util.TreeSet; + /** * The UniqueCharacterChecker class provides a method to check if all characters * in a given word are unique. @@ -14,7 +18,26 @@ 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; + + /* + hashset only unqiue values + try making a counter to see if it as been seen + loop through the word get its .length() + + go through each of the letters and check to see if it has appeared more than once + + return true or false whether there are duplicate characters + */ + Set seen = new HashSet<>(); + for (int i = 0; i < word.length(); i++) { + if (seen.contains(word.charAt(i))) { + return false; + } + seen.add(word.charAt(i)); + } + + + return true; } public static void main(String[] args) {