594. Longest Harmonious Subsequence

来源:互联网 发布:数据侠客行网盘 编辑:程序博客网 时间:2024/06/06 09:47
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])

        return ans

求最大值和最小值之间相差1的最长子序列的长度。

即求连续两个数的总个数最大

原创粉丝点击