# Leetcode 594 - Longest Harmonious Subsequence

`Note:`

- Sliding window
- While
`nums[j] - nums[i] <= 1`

, compare with maxLen and move`j`

by 1. - While
`nums[j] - nums[i] > 1`

, move`i`

until`nums[j] - nums[i] <= 1`

.

- While
- Hash table
- Put all nums with counts into a map.
- For each [key,val], search
`key + 1`

an`key - 1`

and compare len;

`Question:`

We define a `harmonious`

array as an array where the difference between its maximum value and its minimum value is `exactly 1`

.

Given an integer array `nums`

, return the length of its longest harmonious subsequence among all its possible subsequences.

A `subsequence`

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.

`Example:`

1 | Input: nums = [1,3,2,2,5,2,3,7] |

`Code:`

`Sliding window O(NlogN)`

1 | var findLHS = function(nums) { |

`Hash table O(N)`

1 | /** |