Created
April 6, 2026 15:18
-
-
Save ksamirdev/2b079ac0df811448a0db7ddea4873e1b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def longestConsecutive(self, nums: List[int]) -> int: | |
| s = set(nums) | |
| longest = 0 | |
| for num in s: | |
| if num - 1 not in s: | |
| next_num = num + 1 | |
| length = 1 | |
| while next_num in s: | |
| length += 1 | |
| next_num += 1 | |
| longest = max(longest, length) | |
| return longest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment