[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 ...
随机推荐
- centos docker-ce安装
懂得自然懂 https://yeasy.gitbooks.io/docker_practice/content/install/centos.html
- tensorflow 使用 1 常量,变量
import tensorflow as tf #创建一个常量 op 一行二列 m1 = tf.constant([[3, 3]]) #创建一个常量 op 二行一列 m2 = tf.constant( ...
- MyBatis3系列__03几个常用的属性配置
本文主要讲几个xml配置属性: 其都写在mybatis配置文件中 1.properties属性:其作用主要是可以动态引进外部的配置文件中的相关配置 resource:引入类路径下的资源 url:引入网 ...
- Tesseract-ocr 工具使用记录
1.很多地方可以下载Tesseract-ocr工具,同时下载jTessBoxEditor方便之后的训练使用 2.下载Tesseract-ocr后可以放在任何地方,但是需要设置环境变量,或者在CMD当中 ...
- gym 101628
前几天感冒了三天没怎么写题...今天好很多了打个三星场找点手感. 不行啊我好菜啊.只会8个..补题的话,再说吧.G题感觉值得一补. 补了G,K不想写B不会. 说实话这个三星场还是很新人向的,知识点也蛮 ...
- Keepalived+Nginx实现高可用Web负载均衡
1.安装编译 Nginx 所需的依赖包# yum install gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zli ...
- php调用第三方接口
方式一 $url = 'http://ip.taobao.com/service/getIpInfo.php?ip='.$realip;$data = file_get_contents(" ...
- python Ajax
Ajax一.准备知识JSON1.什么是json JSON 指的是 JavaScript 对象表示法(JavaScript Object Notation) JSON 是轻量级的文本数据交换格式 JSO ...
- ubuntu amd64 的锐捷连接解决办法---武汉大学
昨日博主闲来弄了个ubuntu玩玩,于是上网成了个问题,博主武大信息学部,锐捷上校园网.装的是13.04的amd64. 凑巧在珞珈山水bbs上看到我在解决上网出现问题出现的相同情况,但是没有人回答,于 ...
- [BlueZ] 1、Download install and use the BlueZ and hcitool on PI 3B+
星期日, 02. 九月 2018 11:58下午 - beautifulzzzz 1. Introduction Bluez is the default Bluetooth protocol sta ...