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
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
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最长连续递增序列 (C++/Java)
题目: Given an unsorted array of integers, find the length of longest continuous increasing subsequenc ...
- [LeetCode] Longest Continuous Increasing Subsequence 最长连续递增序列
Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...
- 674. Longest Continuous Increasing Subsequence最长连续递增子数组
[抄题]: Given an unsorted array of integers, find the length of longest continuous increasing subseque ...
- Leetcode674.Longest Continuous Increasing Subsequence最长连续递增序列
给定一个未经排序的整数数组,找到最长且连续的的递增序列. 示例 1: 输入: [1,3,5,4,7] 输出: 3 解释: 最长连续递增序列是 [1,3,5], 长度为3. 尽管 [1,3,5,7] 也 ...
- [Leetcode]674. Longest Continuous Increasing Subsequence
Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...
- 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: ...
随机推荐
- 使用C#编写SqlHelper类
无聊的周末,学习.编码无力.想找点事干但又不知道干点什么,猛然发现自己学过的SqlHelper快忘记了.于是乎虎躯一震心想怎能如此堕落下去,立马打开电脑,双手摸上键盘.写下此文作为学习过程中的复习,并 ...
- CoordinatorLayout的使用
最近项目有一个需求,做出类似闲鱼鱼塘界面的效果.如下图: 所以想到用CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout去搭建此界面. Coor ...
- CentOS文件权限管理
目录 文件属性 chown更改所有者 chgrp更改所属组 文件权限rwx chmod修改权限 默认权限umask 权限判定的顺序 特殊权限SUID,SGID,sticky 隐藏权限chattr,ls ...
- Java基础——集合源码解析 List List 接口
今天我们来学习集合的第一大体系 List. List 是一个接口,定义了一组元素是有序的.可重复的集合. List 继承自 Collection,较之 Collection,List 还添加了以下操作 ...
- MySQL主从同步和读写分离的配置
主服务器:192.168.1.126 从服务器:192.168.1.163 amoeba代理服务器:192.168.1.237 系统全部是CentOS 6.7 1.配置主从同步 1.1.修改主服务器( ...
- 进入css3动画世界(二)
进入css3动画世界(二) 今天主要来讲transition和transform入门,以后会用这两种属性配合做一些动效. 注:本文面向前端css3动画入门人员,我对这个也了解不深,如本文写的有纰漏请指 ...
- 【POJ】2115 C Looooops(扩欧)
Description A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; ...
- 从DDD开始说起
前言 从13年接触DDD之后开始做应用架构已经整整四个年头. 四年里关于DDD的感触良多,慢慢有了一些心得. 关于DDD的介绍已经有很多的文章和书籍,这里我推荐三本最重要的书籍. <领域驱动设计 ...
- Judge Route Circle
Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot m ...
- js自执行函数写法
(1)写法1 (function(){ //函数内容 })() (2)写法2 (function(){ //函数内容 }())