-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
34 lines (27 loc) · 741 Bytes
/
Copy pathSolution.java
File metadata and controls
34 lines (27 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package org.example.problems.contains_duplicate;
import org.example.problems.SolutionInterface;
import java.util.HashSet;
import java.util.Set;
public class Solution implements SolutionInterface {
@Override
public String getName() {
return "Contains Duplicate";
}
@Override
public String getUrl() {
return "https://leetcode.com/problems/contains-duplicate/";
}
public boolean containsDuplicate(int[] nums) {
if (nums.length < 2) {
return false;
}
Set<Integer> set = new HashSet<>();
for (int i : nums) {
if (set.contains(i)) {
return true;
}
set.add(i);
}
return false;
}
}