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)