Skip to content

Commit 4212d9b

Browse files
committed
add solution of longest-consecutive-sequence
1 parent 8031e40 commit 4212d9b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package week01.longest_consecutive_sequence;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class Solution {
7+
8+
public boolean containsDuplicate(int[] nums) {
9+
10+
Map<Integer, Integer> countMap = new HashMap<>();
11+
12+
for (int i = 0; i < nums.length; i++) {
13+
countMap.put(nums[i], countMap.getOrDefault(nums[i] , 0) + 1);
14+
}
15+
16+
for (Map.Entry<Integer, Integer> map : countMap.entrySet()) {
17+
if (map.getValue() >= 2) {
18+
return true;
19+
}
20+
}
21+
22+
return false;
23+
}
24+
}

0 commit comments

Comments
 (0)