class Solution(object):
def findLHS(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
count = collections.Counter(nums)
ans = 0
for x in count:
if x+1 in count:
ans = max(ans, count[x] + count[x+1])
def findLHS(self, nums):
"""
:type nums: List[int]
:rtype: 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
求最大值和最小值之间相差1的最长子序列的长度。
即求连续两个数的总个数最大