Skip to content

Commit e136a60

Browse files
authored
Update longest-harmonious-subsequence.py
1 parent 12f7ddd commit e136a60

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

Python/longest-harmonious-subsequence.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
# Time: O(n)
22
# Space: O(n)
33

4+
# We define a harmonious array is an array where the difference
5+
# between its maximum value and its minimum value is exactly 1.
6+
#
7+
# Now, given an integer array, you need to find the length of its
8+
# longest harmonious subsequence among all its possible subsequences.
9+
#
10+
# Example 1:
11+
# Input: [1,3,2,2,5,2,3,7]
12+
# Output: 5
13+
# Explanation: The longest harmonious subsequence is [3,2,2,2,3].
14+
# Note: The length of the input array will not exceed 20,000.
15+
416
class Solution(object):
517
def findLHS(self, nums):
618
"""

0 commit comments

Comments
 (0)