Find the count of the longest consecutive numbers in an array and optimize it using collections.
Implement longest_consecutive(nums) to return the length of the longest sequence of consecutive integer values. Treat duplicate values as one value, and return 0 for an empty array. The input is a list of integers, and the output is an integer.
Examples: nums = [100, 4, 200, 1, 3, 2] returns 4, and nums = [1, 2, 2, 3] returns 3.
def longest_consecutive(nums):