Skip to content

Commit 3d815af

Browse files
committed
contains-duplicate Set 방식으로 변경
1 parent 8436024 commit 3d815af

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

contains-duplicate/mintheon.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import java.util.Arrays;
1+
import java.util.HashSet;
2+
import java.util.Set;
23

34
class Solution {
45
public boolean containsDuplicate(int[] nums) {
5-
Arrays.sort(nums);
6-
for(int i = 1; i < nums.length; i++) {
7-
if(nums[i] == nums[i - 1]) {
8-
return true;
9-
}
6+
Set<Integer> numSet = new HashSet();
7+
8+
for(int num : nums) {
9+
numSet.add(num);
1010
}
11-
return false;
11+
12+
return numSet.size() != nums.length;
1213
}
1314
}

0 commit comments

Comments
 (0)