Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf3b3898

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 parent38e0811 commitf3b3898

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
classSolution {
22
publicbooleancontainsDuplicate(int[]nums) {
3-
Set<Integer>numbers =newHashSet<Integer>();
4-
for (intnum :nums) {
5-
if (numbers.contains(num))returntrue;
6-
numbers.add(num);
3+
Set<Integer>uniques =newHashSet<>();
4+
for (finalintnum :nums) {
5+
if (!uniques.add(num)) {
6+
returntrue;
7+
}
78
}
8-
99
returnfalse;
1010
}
11-
}
11+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp