longest_consecutive
longest_consecutive.go 源码
package leetcode
func longestConsecutive(nums []int) int {
m := make(map[int]bool)
for _, v := range nums {
m[v] = true
}
res := 0
for v := range m {
if !m[v-1] {
cur, curRes := v, 1
for m[cur+1] {
curRes++
cur++
}
if curRes > res {
res = curRes
}
}
}
return res
}
你可能感兴趣的文章
0
赞
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦