Skip to content

Commit a7576f3

Browse files
committed
[TONY] WEEK 01 solutions
1 parent ee1ad8e commit a7576f3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

contains-duplicate/TonyKim9401.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public boolean containsDuplicate(int[] nums) {
3+
// HashSet O(n)
4+
/*
5+
Set<Integer> set = new HashSet();
6+
for (int num : nums) set.add(num);
7+
return set.size() != nums.length;
8+
*/
9+
10+
// dupl value O(n log n)
11+
Arrays.sort(nums);
12+
for (int i = 0; i < nums.length - 1; i++) {
13+
if (nums[i] == nums[i + 1]) return true;
14+
}
15+
return false;
16+
}
17+
}

0 commit comments

Comments
 (0)