Longest Harmonious Subsequence
Input:
[1,3,2,2,5,2,3,7]
Output:
5
Explanation:
The longest harmonious subsequence is [3,2,2,2,3].class Solution(object):
def findLHS(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
hashmap = collections.Counter(nums)
result = 0
for i in hashmap:
if i+1 in hashmap:
result = max(result, hashmap[i]+hashmap[i+1])
return resultLast updated