LeetCode 674. Longest Continuous Increasing Subsequence (最长连续递增序列)
2024-10-19 00:25:40
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
class Solution
{
public int findLengthOfLCIS(int[] nums)
{
if(nums == null || nums.length == 0)
return 0; int maxLen = 0;
int tempLen = 1; for(int i=1; i<nums.length; i++)
{
if(nums[i] <= nums[i-1])
{
maxLen = Math.max(maxLen, tempLen);
tempLen = 1;
}
else
{
tempLen++;
} } return Math.max(maxLen, tempLen);
}
}
参考资料:N/A
LeetCode 题目列表 - LeetCode Questions List
最新文章
- 【JSP手记】--jsp里面session.getAttribute(";&#215;&#215;&#215;";)在java中的表示
- hdu4920 Matrix multiplication 模3矩阵乘法
- RST_n的问题
- 获得View的真实高度
- node-gyp rebuild 卡住?
- C++ STL初学笔记
- pci 记录
- 使用Xcode查找项目中的中文字符串
- (step4.3.1) hdu 1010(Tempter of the Bone——DFS)
- 如何在pl/sql developer 7运行到oracle存储过程设置断点的地方
- 清华集训2014 day2 task1 简单回路
- Jedis-returnResource使用注意事项
- 自定义Retrofit转化器Converter
- activiti源码编译
- YTKNetwork网络封装
- Java面试总结(集合、spring)
- 【使用指南】WijmoJS 前端开发工具包
- kickstart自动安装部署RHEL7
- consul在windows下的安装
- MVC与MVVM设计模式理解