We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ee1ad8e commit a053d8cCopy full SHA for a053d8c
contains-duplicate/TonyKim9401.java
@@ -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