removed 1 map

This commit is contained in:
Gleb Koval 2022-07-06 21:04:31 +01:00
parent 0c78e204ef
commit c2b6b2f070
Signed by: cyclane
GPG Key ID: 15E168A8B332382C
1 changed files with 4 additions and 5 deletions

View File

@ -5,21 +5,20 @@ func longestConsecutive(nums []int) (max int) {
for _, n := range nums {
exists[n] = true
}
done := make(map[int]bool, len(nums))
for _, n := range nums {
if _, ok := done[n]; !ok {
done[n] = true
if _, ok := exists[n]; ok {
exists[n] = false
l := 1
for exists[n+1] {
l++
n++
done[n] = true
exists[n] = false
}
n -= l - 1
for exists[n-1] {
l++
n--
done[n] = true
exists[n] = false
}
if l > max {
max = l