Skip to content

Latest commit

 

History

History
64 lines (44 loc) · 991 Bytes

[0594] 最长和谐子序列.md

File metadata and controls

64 lines (44 loc) · 991 Bytes
title tags categories author comments updated permalink mathjax top description date
[0594] 最长和谐子序列
leetcode
leetcode
张学志
true
false
false
false
...
2019-12-31 16:09:54 -0800

题目描述

和谐数组是指一个数组里元素的最大值和最小值之间的差别正好是1。

现在,给定一个整数数组,你需要在所有可能的子序列中找到最长的和谐子序列的长度。

示例 1:

输入: [1,3,2,2,5,2,3,7]
输出: 5
原因: 最长的和谐数组是:[3,2,2,2,3].

说明: 输入的数组长度最大不超过20,000.

Related Topics
  • 哈希表
  • 题目代码

    class Solution {
    public:
        int findLHS(vector<int>& nums) {
    
        }
    };

    题目解析

    方法一

    方法二

    方法三