594.Longest Harmonious Subsequence
594.Longest Harmonious Subsequence
难度:Easy
We define a harmounious array as an array where the difference between its maximum value and its minimum value is exactly 1.
Now, given an integer array, you need to find the length of its longest harmonious subsequence among all its possible subsequences.
Example 1:
Note: The length of the input array will not exceed 20,000.
采用hashMap统计每个数出现的次数,然后比较相邻两个数出现次数之和,求出最大值即可。
执行用时 :116 ms, 在所有 C++ 提交中击败了80.28%的用户 内存消耗 :19.6 MB, 在所有 C++ 提交中击败了76.63%的用户
Last updated