Skip to content

Commit fcf00a4

Browse files
solves comtains duplicate
1 parent 3bc16ed commit fcf00a4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/ContainsDuplicate.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import java.util.HashSet;
2+
import java.util.Set;
3+
4+
public class ContainsDuplicate {
5+
public static boolean containsDuplicate(int[] array) {
6+
Set<Integer> elements = new HashSet<>();
7+
for (int element : array) {
8+
if (elements.contains(element)) {
9+
return true;
10+
}
11+
elements.add(element);
12+
}
13+
return false;
14+
}
15+
}

0 commit comments

Comments
 (0)