Class Solution
java.lang.Object
g0501_0600.s0594_longest_harmonious_subsequence.Solution
594 - Longest Harmonious Subsequence.<p>Easy</p>
<p>We define a harmonious array as an array where the difference between its maximum value and its minimum value is <strong>exactly</strong> <code>1</code>.</p>
<p>Given an integer array <code>nums</code>, return <em>the length of its longest harmonious subsequence among all its possible subsequences</em>.</p>
<p>A <strong>subsequence</strong> of array is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [1,3,2,2,5,2,3,7]</p>
<p><strong>Output:</strong> 5</p>
<p><strong>Explanation:</strong> The longest harmonious subsequence is [3,2,2,2,3].</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [1,2,3,4]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums = [1,1,1,1]</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 2 * 10<sup>4</sup></code></li>
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
findLHS
public int findLHS(int[] nums)
-