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 {
|
for _, n := range nums {
|
||||||
exists[n] = true
|
exists[n] = true
|
||||||
}
|
}
|
||||||
done := make(map[int]bool, len(nums))
|
|
||||||
for _, n := range nums {
|
for _, n := range nums {
|
||||||
if _, ok := done[n]; !ok {
|
if _, ok := exists[n]; ok {
|
||||||
done[n] = true
|
exists[n] = false
|
||||||
l := 1
|
l := 1
|
||||||
for exists[n+1] {
|
for exists[n+1] {
|
||||||
l++
|
l++
|
||||||
n++
|
n++
|
||||||
done[n] = true
|
exists[n] = false
|
||||||
}
|
}
|
||||||
n -= l - 1
|
n -= l - 1
|
||||||
for exists[n-1] {
|
for exists[n-1] {
|
||||||
l++
|
l++
|
||||||
n--
|
n--
|
||||||
done[n] = true
|
exists[n] = false
|
||||||
}
|
}
|
||||||
if l > max {
|
if l > max {
|
||||||
max = l
|
max = l
|
||||||
|
|
Loading…
Reference in New Issue