Longest Harmonious Subsequence

利用哈希表计数再判断相邻一个数是否存在就行

class Solution(object):
    def findLHS(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        tmp = collections.Counter(nums)
        result = 0
        for key, value in tmp.iteritems():
            if key + 1 in tmp:
                result = max(result, value + tmp[key + 1])
        return result

results matching ""

    No results matching ""