Skip to content

Commit df83c3f

Browse files
authored
Update 217-Contains-Duplicate.java
Use the return value of `add` function in `Set` instead of using `contains` and `add` function separately.
1 parent fc1ac34 commit df83c3f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

java/217-Contains-Duplicate.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
class Solution {
22
public boolean containsDuplicate(int[] nums) {
3-
Set<Integer> numbers = new HashSet<Integer>();
4-
for (int num : nums) {
5-
if (numbers.contains(num)) return true;
6-
numbers.add(num);
3+
Set<Integer> uniques = new HashSet<>();
4+
for (final int num : nums) {
5+
if (!uniques.add(num)) {
6+
return true;
7+
}
78
}
8-
99
return false;
1010
}
11-
}
11+
}

0 commit comments

Comments
 (0)