Skip to content
Merged
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
16 changes: 16 additions & 0 deletions contains-duplicate/toychip.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import java.util.HashSet;
import java.util.Set;

class Solution {
public boolean containsDuplicate(int[] nums) {
Set<Integer> answer = new HashSet<>();
for (int num : nums) {
if (!answer.contains(num)) {
answer.add(num);
} else {
return true;
}
}
return false;
}
}
12 changes: 12 additions & 0 deletions two-sum/toychip.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution {
public int[] twoSum(int[] nums, int target) {
for (int i = 0; i < nums.length; i++) {
for (int j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] == target) {
return new int[]{i, j};
}
}
}
return null;
}
}