Leetcode 594 Solution
This article provides solution to leetcode question 594 (longest-harmonious-subsequence)
Access this page by simply typing in "lcs 594" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/longest-harmonious-subsequence
Solution
class Solution:
def findLHS(self, nums: List[int]) -> int:
m = collections.Counter(nums)
ans = 0
for k in m:
if k + 1 not in m:
continue
ans = max(ans, m[k] + m[k + 1])
return ans