class Solution:
    def findLHS(self, nums: List[int]) -> int:
        count = collections.Counter(nums)
        ans = 0
        for x in count:
            if x+1 in count:
                ans = max(ans, count[x] + count[x+1])
        return ans
