LeetCode Longest Continuous Increasing Subsequence
原题链接在这里:https://leetcode.com/problems/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.
题解:
如果当前值比前个值大就count++, 更新res. 否则count清回1.
Time Complexity: O(num.length).
Space: O(1).
AC Java:
class Solution {
public int findLengthOfLCIS(int[] nums) {
if(nums == null || nums.length == 0){
return 0;
}
int count = 1;
int res = 1;
for(int i = 1; i<nums.length; i++){
if(nums[i] > nums[i-1]){
count++;
res = Math.max(res, count);
}else{
count = 1;
}
}
return res;
}
}
跟上Number of Longest Increasing Subsequence.
LeetCode Longest Continuous Increasing Subsequence的更多相关文章
- [LeetCode] 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 最长连续递增序列
Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...
- LeetCode 674. 最长连续递增序列(Longest Continuous Increasing Subsequence) 18
674. 最长连续递增序列 674. Longest Continuous Increasing Subsequence 题目描述 给定一个未经排序的整型数组,找到最长且连续的递增序列. Given ...
- 【LeetCode】674. Longest Continuous Increasing Subsequence 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 空间压缩DP 日期 题目地址:https: ...
- [Leetcode]674. Longest Continuous Increasing Subsequence
Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...
- [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最长连续递增序列 (C++/Java)
题目: Given an unsorted array of integers, find the length of longest continuous increasing subsequenc ...
- C#LeetCode刷题之#674-最长连续递增序列( Longest Continuous Increasing Subsequence)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3734 访问. 给定一个未经排序的整数数组,找到最长且连续的的递增 ...
随机推荐
- iOS 优化界面流畅度的探讨
界面流畅度 大都跟list scrollView有紧密关联 流畅的视觉:就是如丝般顺滑 不流畅视觉:”卡顿”,”抖动”,”迟顿感” 以上两种状态的描述 都是基于主观感觉,对于开发者来说 确实应该有一个 ...
- c# 接口(interface)与接口应用
using System; using System.Collections.Generic; using System.Linq; using System.Text; //接口(interface ...
- Python学习进程(10)字典
本节介绍Python中的字典:是另一种可变容器模型,且可存储任意类型对象. (1)字典简介: 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割 ...
- 玩转python主题模型程序库gensim
gensim是python下一个极易上手的主题模型程序库(topic model),网址在:http://radimrehurek.com/gensim/index.html 安装过程较为繁琐,参考h ...
- 建议44:理解模块pickle优劣
# -*- coding:utf-8 -*- ''' pickle 估计是最通用的序列化模块了,它还有个C 语言的实现cPickle,相比pickle 来说 具有较好的性能,其速度大概是pickle ...
- 【HackerRank】Maximizing XOR
给定两个整数:L 和 R ∀ L ≤ A ≤ B ≤ R, 找出 A xor B 的最大值. 输入格式 第一行包含 L 第一行包含 R 数据范围 1 ≤ L ≤ R ≤ 103 输出格式 输出最大的异 ...
- HTTP协议—HTTP响应头和请求头
HTTP请求头提供了关于请求,响应或者其他的发送实体的信息. HTTP的头信息包括通用头.请求头.响应头和实体头四个部分.每个头域由一个域名,冒号(:)和域值三部分组成. 通用头标:即可用于请求,也可 ...
- Python 元组Tuple概念和操作
# 元组概念:有序的不可变的元素集合 # 和列表的区别就是, 元组元素不能修改 # 定义 # 一个元素的写法 # (666,) t = (666,) #正确写法 t = (666) #错误写法,括号当 ...
- thinkphp 多表事务处理
try{ $this->user = D('User'); $this->user->startTrans(); //开始事务 $res = $this->user->S ...
- EasyUI学习
1.基础知识: 1)Parser解析器: div指定了class后能有效果是因为开始时文档时加载DOM但是一些由js动态生成的指定了class的div没有被解析此时就需要手动解析了 js动态生成的指定 ...