Skip to content

Commit

Permalink
[TONY] WEEK 01 solutions
Browse files Browse the repository at this point in the history
Comment: containsDuplicate
  • Loading branch information
TonyKim9401 committed Aug 11, 2024
1 parent ee1ad8e commit 5bd8c0e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions contains-duplicate/TonyKim9401.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public boolean containsDuplicate(int[] nums) {
// HashSet O(n)
/*
Set<Integer> set = new HashSet();
for (int num : nums) set.add(num);
return set.size() != nums.length;
*/

// dupl value O(n log n)
Arrays.sort(nums);
for (int i = 0; i < nums.length - 1; i++) {
if (nums[i] == nums[i + 1]) return true;
}
return false;
}
}

0 comments on commit 5bd8c0e

Please sign in to comment.