Skip to content

Commit 23984e6

Browse files
committed
refactor: contains-duplicate solution
1 parent 115c0e3 commit 23984e6

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

contains-duplicate/sm9171.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ public boolean containsDuplicate(int[] nums) {
33
HashSet<Integer> set = new HashSet<>();
44

55
for (int i = 0; i < nums.length; i++) {
6+
if (set.contains(nums[i])) {
7+
return true;
8+
}
69
set.add(nums[i]);
710
}
8-
9-
if (nums.length == set.size()) {
10-
return false;
11-
}
12-
return true;
11+
return false;
1312
}
1413
}

0 commit comments

Comments
 (0)