Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func longestConsecutive(nums []int) int {
- numSet:=map[int]bool{}
- for _,v:=range nums {
- numSet[v] = true
- }
- longest := 0
- for num:=range numSet {
- if numSet[num - 1] {
- continue
- }
- cur :=num
- for numSet[cur+1] {
- cur++
- }
- longest = max(longest,cur - num + 1)
- }
- return longest
- }
- func max(a, b int)int{
- if a > b{
- return a
- }
- return b
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement