Longest Consecutive Sequence (LC-0128)

class Solution:
    def longestConsecutive(self, nums):
        cmax = 0
        cache = set(nums)

        for n in cache:
            if n - 1 not in cache:
                curr = n + 1
                while curr in cache:
                    curr = curr + 1
                cmax = max(cmax, curr - n)
        
        return cmax