12 lines python solution,beat 95%


  • 0
    C
    def longestConsecutive(self, nums):
        if not nums:
            return 0
        Set=set(nums)
        res=1
        while Set:
            Max=max(Set)
            temp=Max
            while temp in Set:
                Set.remove(temp)
                temp-=1
            res=max(res,Max-temp)
        return res

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.