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 4ddd37e commit 2231fb0Copy full SHA for 2231fb0
contains-duplicate/Sol35229.java
@@ -0,0 +1,27 @@
1
+import java.util.Arrays;
2
+import java.util.HashSet;
3
+import java.util.Set;
4
+
5
+public class Sol35229 {
6
7
+ public boolean containsDuplicate(int[] nums) {
8
+ Set<Integer> duplicateCheck = new HashSet<>();
9
+ for (int i = 0; i < nums.length; i++) {
10
+ if (duplicateCheck.contains(nums[i])) {
11
+ return true;
12
+ }
13
+ duplicateCheck.add(nums[i]);
14
15
+ return duplicateCheck.size() != nums.length;
16
17
18
+ public boolean containsDuplicate2(int[] nums) {
19
+ Arrays.sort(nums);
20
+ for (int i = 0; i < nums.length-1; i++) {
21
+ if (nums[i] == nums[i+1]) {
22
23
24
25
+ return false;
26
27
+}
0 commit comments