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 fc1ac34 commit df83c3fCopy full SHA for df83c3f
java/217-Contains-Duplicate.java
@@ -1,11 +1,11 @@
1
class Solution {
2
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);
+ Set<Integer> uniques = new HashSet<>();
+ for (final int num : nums) {
+ if (!uniques.add(num)) {
+ return true;
7
+ }
8
}
-
9
return false;
10
11
-}
+}
0 commit comments