Skip to content

Commit a0edb9f

Browse files
committed
contains duplicate
1 parent 580d05f commit a0edb9f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

contains-duplicate/pastelto.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
Return true when array contains duplicated number
3+
*/
4+
class Solution {
5+
public boolean containsDuplicate(int[] nums) {
6+
HashSet<Integer> set = new HashSet<>();
7+
8+
for (int num : nums) {
9+
if (set.contains(num)) return true;
10+
set.add(num);
11+
}
12+
return false;
13+
}
14+
}

0 commit comments

Comments
 (0)