1 class Solution:
 2     def longestConsecutive(self, nums: 'List[int]') -> int:
 3         if len(nums)<=1:
 4             return len(nums)
 5 
 6         nums2 = sorted(set(nums))
 7         pre = nums2[0]
 8         maxc = 0
 9         curc = 1
10         for i in range(1,len(nums2)):
11             if nums2[i] == pre + 1:
12                 curc += 1
13             else:
14                 maxc = max(maxc,curc)
15                 curc = 1
16             pre = nums2[i]
17         return max(maxc,curc)

 

posted on 2019-03-04 20:03  Sempron2800+  阅读(168)  评论(0编辑  收藏  举报