We define a harmonious array is 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.
解法1:
对于subsequence的题目,经常会用到two pointer,一种是从两头像中间靠拢,另一种是前后两个指针按照条件和数字的变化不停的移动。这题就属于后者。
C++
Java