removed 1 map
This commit is contained in:
parent
0c78e204ef
commit
c2b6b2f070
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue