...

```
public int longestConsecutive(int[] nums) {
Map<Integer, Integer> map = new HashMap<>();
boolean[] visited = new boolean[nums.length];
for (int i = 0; i < nums.length; i++) {
if (!map.containsKey(nums[i]))
map.put(nums[i], i);
else
visited[i] = true;
}
int cnt = 0;
for (int i = 0; i < nums.length; i++) {
if (!visited[i]) {
visited[i] = true;
int localCnt = 1;
for (int j = nums[i]-1; map.containsKey(j); localCnt++, visited[map.get(j--)]=true);
for (int j = nums[i]+1; map.containsKey(j); localCnt++, visited[map.get(j++)]=true);
cnt = localCnt > cnt ? localCnt : cnt;
}
}
return cnt;
}
```

...