674. Longest Continuous Increasing Subsequence

406 篇文章 0 订阅
406 篇文章 0 订阅

1,题目要求
Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray).
这里写图片描述
找到一个连续的最长递增子序列。
2,题目思路
还是利用了动态规划的基本思想。动态去依次寻找最长的递增子序列。设置一个count变量来记录每次满足递增条件的子序列的长度,然后利用maxLen变量来记录查找到某个数字时可以实现的最长的序列长度。
3,程序源码

class Solution {
public:
    int findLengthOfLCIS(vector<int>& nums) {
        if(nums.size()==0)
            return 0;

        int maxLen = 1;
        int minNum = nums[0];
        int count = 1;

        for(int i=1;i<nums.size();i++)
        {
            if(nums[i]>nums[i-1])
            {
                count ++;
                maxLen = max(count, maxLen);
            }
            else
            {
                count = 1;//对长度进行重置
            }
        }
        return maxLen;
    }
};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值