[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.
思路:如果数组的长度小于2,则直接返回数组的长度;否则设置两个变量maxLength=1和length=1,length用于统计
连续递增的子序列长度,一旦递增中断,则lenth重置为1,继续后面的统计。这个过程中,最大的length值赋给maxLength
class Solution {
public int findLengthOfLCIS(int[] nums) {
if (nums.length<2)
return nums.length;
int maxLength = 1,length = 1;
for (int i=1;i<nums.length;i++){
if (nums[i]>nums[i-1])
length++;
else
length = 1;
if (length>maxLength)
maxLength = length;
}
return maxLength;
}
}
[Leetcode]674. Longest Continuous Increasing Subsequence的更多相关文章
- [LeetCode] 674. Longest Continuous Increasing Subsequence 最长连续递增序列
Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...
- LeetCode 674. Longest Continuous Increasing Subsequence (最长连续递增序列)
Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...
- LeetCode 674. Longest Continuous Increasing Subsequence最长连续递增序列 (C++/Java)
题目: Given an unsorted array of integers, find the length of longest continuous increasing subsequenc ...
- leetcode300. Longest Increasing Subsequence 最长递增子序列 、674. Longest Continuous Increasing Subsequence
Longest Increasing Subsequence 最长递增子序列 子序列不是数组中连续的数. dp表达的意思是以i结尾的最长子序列,而不是前i个数字的最长子序列. 初始化是dp所有的都为1 ...
- 【Leetcode_easy】674. Longest Continuous Increasing Subsequence
problem 674. Longest Continuous Increasing Subsequence solution class Solution { public: int findLen ...
- 【LeetCode】674. Longest Continuous Increasing Subsequence 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 空间压缩DP 日期 题目地址:https: ...
- [LeetCode&Python] Problem 674. Longest Continuous Increasing Subsequence
Given an unsorted array of integers, find the length of longest continuousincreasing subsequence (su ...
- [LeetCode] 674. Longest Continuous Increasing Subsequence_Easy Dynamic Programming
Given an unsorted array of integers, find the length of longest continuous increasing subsequence (s ...
- 674. Longest Continuous Increasing Subsequence最长连续递增子数组
[抄题]: Given an unsorted array of integers, find the length of longest continuous increasing subseque ...
随机推荐
- block学习二:使用Block替代回调
使用Block替代回调,分为三步进行:
- [JZOJ3588]【中山市选2014】J语言(表达式解析+栈)
Description J语言作为一门编程语言,诞生于20世纪90年代.............. 好学的小H今天又学到了一种新东西——J语言.显然,J语言的背景已经被小H忘得一干二净了,但是小H仍然 ...
- springmvc是如何工作的
上图便是springmvc的工作流程,看着条条框框的,其实说的直白一点,springmvc就是负责处理用户的需求(request/url),它的负责人(核心组件)就是前端控制器(DispatcherS ...
- HTMl、CSS、JS的区别:
HTMl.CSS.JS的区别: Html:决定网页的结构和内容----[结构] Css:控制页面的表现样式,如:美化页面----[表现] Js:控制网页的行为,如:给页面加动态的效果----[行为]
- centos7搭建本地 Remix
由于最近要弄加入某联盟链,是基于ETH 所以要弄一个开发环境 一.准备 安装 nodejs,npm,git 二.安装 git clone https://github.com/ethereum/rem ...
- for循环:用turtle画一颗五角星
import turtle # 设置初始位置 turtle.penup() turtle.left(90) turtle.fd(200) turtle.pendown() turtle.right(9 ...
- webpack2入门概念
webpack是一种JavaScript应用模块化打包工具,它配置起来简单易上手,因此很多企业工程化代码都使用它来打包.在具体介绍如何使用webpack之前,先来介绍下webpack的四个核心概念. ...
- 浅谈C++ STL
C++ STL(标准模板库)是一套功能强大的 C++ 模板类,提供了通用的模板类和函数,这些模板类和函数可以实现多种流行和常用的算法和数据结构,如向量.链表.队列.栈. C++ 标准模板库的核心包括以 ...
- 29 ArcMap许可服务器点击授权后无法进入下一步
系统描述:Windows server 2008 R2 ArcMap版本:10.6 系统要求各项都满足,包括补丁包都有,没有杀毒软件,ArcMap软件能安装上,但是到授权那步出问题 系统要求http ...
- 使用ANY和ALL条件
在比较运算符中,可以出现ALL和ANY,表示“全部”和“任一”,但是ALL和ANY不能单独使用,需要配合单行比较操作符>.>=.<.<=一起使用.其中: > ANY : ...