Python super short and easy O(n) solution
\nclass Solution:\n    def longestConsecutive(self, nums: List[int]) -> int:\n        my_dict = defaultdict(int)\n        maxi = 0\n        for num in nums:\n  
```\nclass Solution:\n    def longestConsecutive(self, nums: List[int]) -> int:\n        my_dict = defaultdict(int)\n        maxi = 0\n        for num in nums:\n            if num not in my_dict.keys():\n                prev_ = my_dict.get(num-1, 0)\n                next_ = my_dict.get(num+1, 0)\n                my_dict[num] += prev_ + next_ + 1\n                my_dict[num-prev_] = my_dict[num]\n                my_dict[num+next_] = my_dict[num]\n                maxi = max(maxi, my_dict[num])\n        return maxi\n```\n**Like it? please upvote...**
['Python']