LeetCode 674. Longest Continuous Increasing Subsequence

来源:互联网 发布:js获取file绝对路径 编辑:程序博客网 时间:2024/05/01 00:59

问题描述

Given an unsorted array of integers, find the length of longest continuous increasing subsequence.
Example 1:
Input: [1,3,5,4,7]
Output: 3
Explanation: The longest continuous increasing subsequence is [1,3,5], its length is 3.
Even though [1,3,5,7] is also an increasing subsequence, it’s not a continuous one where 5 and 7 are separated by 4.

Note: Length of the array will not exceed 10,000.

题目描述

给定一个数组,求出最长的连续上升数的长度。
使用一个滑动窗口,当发现下降的时候,就计算最长的长度。否则滑动窗口一直移动。

代码实现

 public int findLengthOfLCIS(int[] nums) {        if (nums == null || nums.length == 0) {            return 0;        }        int left = 0;        int right = 1;        int maxLength = 1;        while (right < nums.length) {            if (nums[right] <= nums[right - 1]) {                maxLength = Math.max(maxLength, (right - left));                left = right;            }            right++;        }        return Math.max(maxLength, (right - left));    }
阅读全文
0 0
原创粉丝点击