Python with Set O(n)
Set is implemented with the hashing mechanism in Python. So the complexity is O(N)\n\n    class Solution(object):\n        def longestConsecutive(self, nums):\n
Set is implemented with the hashing mechanism in Python. So the complexity is O(N)\n\n    class Solution(object):\n        def longestConsecutive(self, nums):\n            """\n            :type nums: List[int]\n            :rtype: int\n            """\n            h = set()\n            for n in nums:\n                h.add(n)\n            ans = 0\n            while h:\n                x = h.pop()\n                count = 1\n                a, b = x-1, x+1\n                while a in h:\n                    count += 1\n                    h.remove(a)\n                    a -= 1\n                while b in h:\n                    count += 1\n                    h.remove(b)\n                    b += 1\n                ans = max(ans, count)\n            return ans
[]