Given an unsorted list of integers nums, find the longest run of numbers that follow each other with a step of 1, such as 5, 6, 7, 8. The numbers can sit anywhere in the list and in any order. Return the length of that longest run.
Your solution must run in O(n) time.
Examples
Example 1:
Input: nums = [50,3,51,2,52,1,4]
Output: 4
Explanation: The run 1, 2, 3, 4 has length 4. The run 50, 51, 52 has length 3. The answer is 4.
Example 2:
Input: nums = [9,1,8,5,7,6,3]
Output: 5
Explanation: The run 5, 6, 7, 8, 9 has length 5.
Example 3:
Input: nums = [10,10,10]
Output: 1
Explanation: The same value repeated counts once. The longest run has length 1.