674. 最长连续递增序列
674. Longest Continuous Increasing Subsequence

题目描述
给定一个未经排序的整型数组,找到最长且连续的递增序列。

Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray).

每日一算法2019/5/21Day 18LeetCode674. Longest Continuous Increasing Subsequence

示例 1:

输入: [1,3,5,4,7] 输出: 3 解释: 最长连续递增序列是 [1,3,5],长度为 3。 尽管 [1,3,5,7] 也是升序的子序列,但它不是连续的,因为 5 和 7 在原数组里被 4 隔开。

示例 2:

输入: [2,2,2,2,2] 输出: 1 解释: 最长连续递增序列是 [2],长度为 1。

注意: 数组长度不会超过 10000。

Java 实现

class Solution {
    public int findLengthOfLCIS(int[] nums) {
        int res = 0, cnt = 0;
        for (int i = 0; i < nums.length; i++) {
            if (i == 0 || nums[i - 1] < nums[i]) {
                res = Math.max(res, ++cnt);
            } else {
                cnt = 1;
            }
        }
        return res;
    }
}

相似题目

参考资料

相关文章:

  • 2021-12-31
  • 2022-12-23
  • 2021-12-13
  • 2021-08-24
  • 2021-07-22
  • 2021-08-29
  • 2021-06-08
  • 2021-08-15
猜你喜欢
  • 2021-09-07
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
  • 2021-08-12
  • 2021-06-25
  • 2022-12-23
相关资源
相似解决方案