Please solve the programming task below using a self-contained code snippet in a markdown code block.

Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.
You must write an algorithm that runs in O(n) time.
 
Please complete the following python code precisely:
```python
class Solution:
    def longestConsecutive(self, nums: List[int]) -> int:
```