# Longest Consecutive Sequence (Leetcode 128)

Problem Link: <https://leetcode.com/problems/longest-consecutive-sequence/>

```python
class Solution:
    def longestConsecutive(self, nums: List[int]) -> int:
        
        d=set(nums)
        ans=0
        for i in nums:
            if(i-1 not in d):
                c=1
                temp=i
                while(temp+1 in d):
                    c+=1
                    temp+=1
                ans=max(ans,c)
        return ans
```
