Description

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.

Example

Example 1:

Input: [5, 4, 2, 1, 3]
Output: 4
Explanation:
For [5, 4, 2, 1, 3], the LICS is [5, 4, 2, 1], return 4.

Example 2:

Input: [5, 1, 2, 3, 4]
Output: 4
Explanation:
For [5, 1, 2, 3, 4], the LICS is [1, 2, 3, 4], return 4.

思路:本题为直接去找一个数组的最长连续上升/下降子序列,直接从左往右枚举即可,每次到单调性变化的时候更新答案。
public class Solution {
public int longestIncreasingContinuousSubsequence(int[] A) {
if (A == null || A.length == 0) {
return 0;
} int n = A.length;
int answer = 1; // from left to right
int length = 1; // just A[0] itself
for (int i = 1; i < n; i++) {
if (A[i] > A[i - 1]) {
length++;
} else {
length = 1;
}
answer = Math.max(answer, length);
} // from right to left
length = 1;
for (int i = n - 2; i >= 0; i--) {
if (A[i] > A[i + 1]) {
length++;
} else {
length = 1;
}
answer = Math.max(answer, length);
} return answer;
}
}

  


Challenge

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

 

Longest Continuous Increasing Subsequence的更多相关文章

  1. LeetCode 674. Longest Continuous Increasing Subsequence (最长连续递增序列)

    Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...

  2. [LeetCode] Longest Continuous Increasing Subsequence 最长连续递增序列

    Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...

  3. [Swift]LeetCode674. 最长连续递增序列 | Longest Continuous Increasing Subsequence

    Given an unsorted array of integers, find the length of longest continuous increasing subsequence (s ...

  4. [Leetcode]674. Longest Continuous Increasing Subsequence

    Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...

  5. [LeetCode&Python] Problem 674. Longest Continuous Increasing Subsequence

    Given an unsorted array of integers, find the length of longest continuousincreasing subsequence (su ...

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

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

  7. 674. Longest Continuous Increasing Subsequence最长连续递增子数组

    [抄题]: Given an unsorted array of integers, find the length of longest continuous increasing subseque ...

  8. LeetCode Longest Continuous Increasing Subsequence

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

  9. 674. Longest Continuous Increasing Subsequence@python

    Given an unsorted array of integers, find the length of longest continuous increasing subsequence (s ...

  10. LeetCode 674. Longest Continuous Increasing Subsequence最长连续递增序列 (C++/Java)

    题目: Given an unsorted array of integers, find the length of longest continuous increasing subsequenc ...

随机推荐

  1. netty 实现心跳检查--断开重连--通俗易懂

    一.心跳介绍 网络中的接收和发送数据都是使用操作系统中的SOCKET进行实现.但是如果此套接字已经断开,那发送数据和接收数据的时候就一定会有问题. 1.心跳机制: 是服务端和客户端定时的发送一个心跳包 ...

  2. [Visual Studio] - 使用 Fiddler 时,禁止监控 VSHub 请求的方法

    背景 VS + Fiddler 调试 WebAPI,监控请求包含大量 VSHub Request.http://localhost:49161/vshub/bb195f2e0d5c4765b9411f ...

  3. QT http请求数据

    1.创建一个请求类(HttpWork): HttpWork.h头文件 #pragma once #include <QObject> #include <QNetworkAccess ...

  4. mysql数据库,数据表,数据的增删查改语句

    查询mysql支持的引擎 show engines; 查询mysql支持的字符集 show character set; 设置mysql默认存储引擎 set default_storage_engin ...

  5. ubuntu 安装 Java 开发环境

    可以使用命令 -jre-headless 或者使用:   本文链接:https://blog.csdn.net/sangewuxie/article/details/80958611 本人的ubunt ...

  6. linux命令行删除N天前的数据的命令

    命令:  find . -mtime +N -type f -name "*.log.*" -exec rm -f {} \; 简单解释: find .查询  ; -mtime 规 ...

  7. 整合MyBatis

    配置数据源相关属性(见前一章节 DataSource配置) 引入依赖 <dependency> <groupId>org.mybatis.spring.boot</gro ...

  8. docker registry-v2 搭建私有仓库

    参考官方文档:https://docs.docker.com/registry/deploying/ 参考 :http://www.tuicool.com/articles/6jEJZj 本例子使用两 ...

  9. bom浏览器对象模型(基础)

    页面中有一个顶级对象: document -> 操作页面元素   浏览器中也有个顶级对象: window -> 页面中所有的东西都是属于window的   变量属于window var n ...

  10. What is Verbose Garbage Collection (verbosegc) and How do I Enable it on WebLogic

    问题描述: What is Verbose Garbage Collection (verbosegc) and How do I Enable it on WebLogic 问题分析: 通过添加gc ...