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

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. 

 

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.

 


题目标签:Array

  题目给了一个没有排序的nums array,让我们找到其中最长连续递增序列的长度。

  维护一个maxLen,每次遇到递增数字就tempLen++,遇到一个不是递增数字的话,就把tempLen 和maxLen 中大的保存到maxLen。

 

 

Java Solution:

Runtime beats 69.72% 

完成日期:10/21/2017

关键词:Array

关键点:维护一个maxLen

复制代码
 1 class Solution 
 2 {
 3     public int findLengthOfLCIS(int[] nums) 
 4     {
 5         if(nums == null || nums.length == 0)
 6             return 0;
 7         
 8         int maxLen = 0;
 9         int tempLen = 1;
10         
11         for(int i=1; i<nums.length; i++)
12         {
13             if(nums[i] <= nums[i-1])
14             {
15                 maxLen = Math.max(maxLen, tempLen);
16                 tempLen = 1;
17             }
18             else
19             {
20                 tempLen++;
21             }
22             
23         }
24         
25         return Math.max(maxLen, tempLen);
26     }
27 }
复制代码

参考资料:N/A

 

LeetCode 题目列表 - LeetCode Questions List

 

posted @   Jimmy_Cheng  阅读(671)  评论(0编辑  收藏  举报
编辑推荐:
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
阅读排行:
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(四):结合BotSharp
· Vite CVE-2025-30208 安全漏洞
· 《HelloGitHub》第 108 期
· MQ 如何保证数据一致性?
· 一个基于 .NET 开源免费的异地组网和内网穿透工具
点击右上角即可分享
微信分享提示