我们定义一个和数组为一个数组,其中最大值和最小值之间的差别是1.给出整数数组的数量,返回其所有可能的子序列中最长的和子序列的长度.一个子序列的数组是可以通过删除一些元素或没有元素而从数组中导出的序列,而不会改变剩余元素的顺序.
To solve this problem, you can use a hash map to count the frequency of each number in the input array. Then, iterate through the keys of the hash map and check if the hash map contains a key that is equal to the current key plus 1. If so, the length of the harmonious subsequence for those two keys is the sum of their frequencies. Keep track of the maximum length seen so far and return it at the end. 

Here's some sample code:

```
def findLHS(nums):
    if not nums:
        return 0
    
    freq = {}
    for num in nums:
        freq[num] = freq.get(num, 0) + 1
        
    max_len = 0
    for key in freq.keys():
        if key + 1 in freq:
            max_len = max(max_len, freq[key] + freq[key+1])
            
    return max_len
```