Longest Consecutive Sequence

Problem Summary

(Write in your own words, not copied from LeetCode. This forces comprehension.)

Why This Works

(Explain the core reason the solution is correct.)

Main Concepts Used

(Mark the CS concepts or algorithms used.)

Time & Space Complexity

Code

class Solution:
    def longestConsecutive(self, nums: List[int]) -> int:
        mySet = set(nums)
        longestSequence = 0

        for num in mySet:
            if (num - 1) in mySet:
                continue
            else:
                currentSequence = 0
                currentNum = num
                while currentNum in mySet:
                    currentSequence += 1
                    currentNum += 1
                longestSequence = max(longestSequence, currentSequence)

        return longestSequence

Common Mistakes / Things I Got Stuck On