[LeetCode]Longest Continuous Increasing Subsequence 最长连续增长序列

简介: 链接:https://leetcode.com/problems/longest-continuous-increasing-subsequence/description/难度:Easy题目:674.

链接https://leetcode.com/problems/longest-continuous-increasing-subsequence/description/
难度:Easy
题目:674. Longest Continuous Increasing Subsequence
Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray).
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. 

Example 2:

Input: [2,2,2,2,2]
Output: 1
Explanation: The longest continuous increasing subsequence is [2], its length is 1. 

Note:

  • Length of the array will not exceed 10,000.

翻译:给定一个无序整型数组,找出最长的连续增长的子序列。

思路:设置一个标志符flag,遍历整个数组,如果后一个值比前一个值大,则res取res和flag中的最大值,否则flag置1。

参考代码
Java

class Solution {
    public int findLengthOfLCIS(int[] nums) {
        if(nums.length <=1)
            return nums.length;
        int res = 0;
        int flag = 0;
        for(int i=0; i<nums.length; i++)
            if(i==0 || nums[i]>nums[i-1])
                res = Math.max(res, ++flag);
            else
                flag = 1;
        return res;
    }
}
目录
相关文章
|
1月前
|
存储 算法
《LeetCode》—— 摆动序列
《LeetCode》—— 摆动序列
|
3月前
|
算法 安全 测试技术
[组合数学]LeetCode:2954:统计感冒序列的数目
[组合数学]LeetCode:2954:统计感冒序列的数目
|
3月前
|
算法 测试技术 C#
【单调栈】LeetCode2030:含特定字母的最小子序列
【单调栈】LeetCode2030:含特定字母的最小子序列
|
1月前
|
存储
力扣187 重复DNA序列
力扣187 重复DNA序列
|
3月前
代码随想录 Day44 动规12 LeetCode T300 最长递增子序列 T674 最长连续递增序列 T718 最长重复子数组
代码随想录 Day44 动规12 LeetCode T300 最长递增子序列 T674 最长连续递增序列 T718 最长重复子数组
43 0
|
3月前
|
Java
leetcode 516. 最长回文子序列(JAVA)题解
leetcode 516. 最长回文子序列(JAVA)题解
23 0
|
3月前
|
算法 测试技术 C#
【二分查找】【双指针】LeetCode:2565最少得分子序列
【二分查找】【双指针】LeetCode:2565最少得分子序列
|
27天前
|
机器学习/深度学习 算法
力扣刷题日常(一)
力扣刷题日常(一)
20 2
|
1月前
|
存储 索引
《LeetCode》—— LeetCode刷题日记
《LeetCode》—— LeetCode刷题日记
|
1月前
|
搜索推荐
《LeetCode》——LeetCode刷题日记3
《LeetCode》——LeetCode刷题日记3

热门文章

最新文章