{{ Swift }} 98% Beat - Using Clever Hash Maps O(N) With O(N) Extra Space
\nclass Solution {\n    func longestConsecutive(_ nums: [Int]) -> Int {\n        var countMap = [Int: Int]()\n        var result = 0\n        for num in nums {\
```\nclass Solution {\n    func longestConsecutive(_ nums: [Int]) -> Int {\n        var countMap = [Int: Int]()\n        var result = 0\n        for num in nums {\n            if countMap[num] == nil {\n                var leftSum = countMap[num - 1] ?? 0\n                var rightSum = countMap[num + 1] ?? 0\n                var streak = leftSum + rightSum + 1\n                countMap[num] = streak\n                if leftSum != 0 { countMap[num-leftSum] = streak }\n                if rightSum != 0 { countMap[num+rightSum] = streak }\n                result = max(result, streak)\n                \n            }\n        }\n        return result\n    }\n}\n```\n\nWorks. Nuff said.
[]