I'm doing the longest consecutive sequence problem on LeetCode (<https://leetcode.com/problems/longest-consecutive-sequence/>) and wrote the following solution:
(I made a typo earlier and put s instead of nums on line 6)

```
class Solution:
    def longestConsecutive(self, nums: List[int]) -> int:
        s = set(nums)
        res = 0

        for n in nums:
            if n - 1 not in nums:
                c = 1

                while n + 1 in s:
                    c += 1
                    n += 1

                res = max(res, c)

        return res

```

This solution takes 4902 ms according to the website, but when I change the first for loop to

```
for n in s:

```

The runtime drops to 491 ms. Is looping through the hashset 10 times faster?