【题目描述】

Give an integer array,find the longest increasing continuous subsequence in this array.

An increasing continuous subsequence:

Can be from right to left or from left to right.

Indices of the integers in the subsequence should be continuous.

Notice:O(n) time and O(1) extra space.

给定一个整数数组(下标从 0 到 n-1, n 表示整个数组的规模),请找出该数组中的最长上升连续子序列。(最长上升连续子序列可以定义为从右到左或从左到右的序列。)

【注】O(n)的时间和O(1)的额外空间。

【题目链接】

www.lintcode.com/en/problem/longest-increasing-continuous-subsequence/

【题目解析】

题目只要返回最大长度,注意此题中的连续递增指的是双向的,即可递增也可递减。简单点考虑可分两种情况,一种递增,另一种递减,跟踪最大递增长度,最后返回即可。也可以在一个 for 循环中搞定,只不过需要增加一布尔变量判断之前是递增还是递减。

【参考答案】

www.jiuzhang.com/solutions/longest-increasing-continuous-subsequence/

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

Lintcode397 Longest Increasing Continuous Subsequence solution 题解的更多相关文章

  1. [LintCode] Longest Increasing Continuous Subsequence 最长连续递增子序列

    Give an integer array,find the longest increasing continuous subsequence in this array. An increasin ...

  2. [LintCode] Longest Increasing Continuous subsequence

    http://www.lintcode.com/en/problem/longest-increasing-continuous-subsequence/# Give you an integer a ...

  3. LintCode 397: Longest Increasing Continuous Subsequence

    LintCode 397: Longest Increasing Continuous Subsequence 题目描述 给定一个整数数组(下标从0到n - 1,n表示整个数组的规模),请找出该数组中 ...

  4. LintCode "Longest Increasing Continuous subsequence II" !!

    DFS + Memorized Search (DP) class Solution { int dfs(int i, int j, int row, int col, vector<vecto ...

  5. Longest Increasing Common Subsequence (LICS)

    最长上升公共子序列(Longest Increasing Common Subsequence,LICS)也是经典DP问题,是LCS与LIS的混合. Problem 求数列 a[1..n], b[1. ...

  6. Lintcode392 Is Subsequence solution 题解

    [题目描述] Given a string s and a string t, check if s is subsequence of t. You may assume that there is ...

  7. leetcode300. Longest Increasing Subsequence 最长递增子序列 、674. Longest Continuous Increasing Subsequence

    Longest Increasing Subsequence 最长递增子序列 子序列不是数组中连续的数. dp表达的意思是以i结尾的最长子序列,而不是前i个数字的最长子序列. 初始化是dp所有的都为1 ...

  8. LeetCode Number of Longest Increasing Subsequence

    原题链接在这里:https://leetcode.com/problems/number-of-longest-increasing-subsequence/description/ 题目: Give ...

  9. 【LeetCode】673. Number of Longest Increasing Subsequence

    题目: Given an unsorted array of integers, find the number of longest increasing subsequence. Example ...

随机推荐

  1. 使用UE4/Unity创建VR项目

    一.主要的步骤是说一下使用UE4,在此之前先说一下使用unity创建的VR项目 1.unity创建oculus rift dk2项目 在unity中创建一个简单的场景,让摄像机能看见场景中的物体,不对 ...

  2. 谈谈Ext JS的组件——组件基类:Ext.Component

    概述 Ext.Component是所有Ext组件的基类,这在Ext.Component的API中第一句话就提到了.然后第二段说明了它包含的基本功能:隐藏/显示.启用/禁用以及尺寸控制等.除了以上这些基 ...

  3. mxGraph进阶(一)mxGraph教程-开发入门指南

    mxGraph教程-开发入门指南 概述 mxGraph是一个JS绘图组件适用于需要在网页中设计/编辑Workflow/BPM流程图.图表.网络图和普通图形的Web应用程序.mxgraph下载包中包括用 ...

  4. 02_Android写xml文件和读xml文件

     新建Android项目 编写AndroidManifest.xml,使本Android项目具有单元测试功能和写外设的权限. <?xml .控制台输出结果

  5. (NO.00001)iOS游戏SpeedBoy Lite成形记(二十三)

    现在还有一个视觉上的问题:玩家每次在游戏开始前选择某一赛道时,无法直观的看到所选的是哪条赛道.只能通过界面上方的gambleLabel中的文字非直观的看到.我们现在来完善它! 为了能让玩家清楚地看到, ...

  6. Mahout系列之----距离度量

       x = (x1,...,xn) 和y = (y1,...,yn) 之间的距离为 (1)欧氏距离   EuclideanDistanceMeasure (2)曼哈顿距离  ManhattanDis ...

  7. OpenCV 使用光流法检测物体运动

    OpenCV 可以使用光流法检测物体运动,贴上代码以及效果. // opticalflow.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" ...

  8. Kotlin For Android 示例代码实战

    下面就为大家介绍怎么使用Kotlin来开发Android 上面这篇中我们在下载Kotlin插件的时候也下了一个功能扩张插件,其实这个插件大有用处,它可以使得我们在不使用注解和第三方库的情况下不使用fi ...

  9. AngularJS进阶(十一)AngularJS实现表格数据的编辑,更新和删除

    AngularJS实现表格数据的编辑,更新和删除 效果 实现 首先,我们先建立一些数据,当然你可以从你任何地方读出你的数据 var app = angular.module('plunker', [' ...

  10. Linux自动安装JDK的shell脚本

    Linux自动安装JDK的shell脚本 A:本脚本运行的机器,Linux B:待安装JDK的机器, Linux 首先在脚本运行的机器A上确定可以ssh无密码登录到待安装jdk的机器B上,然后就可以在 ...