Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/CommonElementsFinder.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import java.util.HashSet;
import java.util.Set;

/**
Expand All @@ -15,7 +16,21 @@ public class CommonElementsFinder {
*/
public static Set<Integer> findCommonElements(int[] array1, int[] array2) {
// TODO
return null;
Set<Integer> hash1 = new HashSet<>();
for (Integer integer : array1) {
hash1.add(integer);
}
Set<Integer> hash2 = new HashSet<>();
for (Integer integer : array2) {
hash2.add(integer);
}
Set<Integer> commonHash = new HashSet<>();
for (Integer integer : hash2) {
if (hash1.contains(integer)) {
commonHash.add(integer);
}
}
return commonHash;
}


Expand Down
15 changes: 13 additions & 2 deletions src/DuplicateRemover.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,8 +17,16 @@ public class DuplicateRemover {
* @return a sorted List<String> containing unique words from the input array
*/
public static List<String> sortAndRemoveDuplicates(String[] words) {
// TODO
return null;
Set<String> unique = new TreeSet<>();
for(String word : words){
unique.add(word);
}
List<String> wordList = new ArrayList<>();
for(String word : unique){
wordList.add(word);
}
return wordList;

}

public static void main(String[] args) {
Expand Down
25 changes: 24 additions & 1 deletion src/UniqueCharacterChecker.java
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<Character> 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) {
Expand Down