594. Longest Harmonious Subsequence

xiaoxiao2021-02-28  73

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的最长子序列的长度。

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

转载请注明原文地址: https://www.6miu.com/read-79819.html

最新回复(0)