最长上升连续子序列-LintCode
来源:互联网 发布:高考改革 知乎 编辑:程序博客网 时间:2024/06/04 22:46
给定一个整数数组(下标从 0 到 n-1, n 表示整个数组的规模),请找出该数组中的最长上升连续子序列。(最长上升连续子序列可以定义为从右到左或从左到右的序列。)
注意:
O(n)时间,O(1)空间
样例:
给定 [5, 4, 2, 1, 3], 其最长上升连续子序列(LICS)为 [5, 4, 2, 1], 返回 4.
给定 [5, 1, 2, 3, 4], 其最长上升连续子序列(LICS)为 [1, 2, 3, 4], 返回 4.
#ifndef C397_H#define C397_H#include<iostream>#include<vector>using namespace std;class Solution {public: /* * @param A: An array of Integer * @return: an integer */ int longestIncreasingContinuousSubsequence(vector<int> &A) { // write your code here if (A.empty()) return 0; int len = A.size(); if (len <= 1) return len; int num = 1,res=1; for (int i = 1; i < len; ++i) { if (A[i]>A[i - 1]) num++; else { res = res > num ? res : num; num = 1; } } res = res > num ? res : num; int count = 1; num = 1; for (int i = len - 2; i >= 0; --i) { if (A[i] > A[i + 1]) num++; else { count = count > num ? count : num; num = 1; } } count = count > num ? count : num; return res > count ? res : count; }};#endif
阅读全文
0 0
- LintCode--最长上升连续子序列
- lintcode-最长上升连续子序列-397
- 最长上升连续子序列(LintCode)
- LintCode- 最长上升连续子序列
- lintCode刷题--最长上升连续子序列
- LintCode:最长上升连续子序列
- lintcode -- 最长上升连续子序列
- lintcode:最长上升连续子序列
- LintCode: 最长上升连续子序列
- Lintcode最长上升连续子序列
- 最长上升连续子序列-LintCode
- 最长上升连续子序列-LintCode
- LintCode 最长上升连续子序列
- lintcode longest-increasing-continuous-subsequence 最长上升连续子序列
- LintCode(easy)最长上升连续子序列
- lintcode——最长上升连续子序列
- [Lintcode 397] 最长上升连续子序列(Python)
- LintCode刷题——最长上升连续子序列
- Django Hello World
- oracle子查询
- office--word使用技巧——论文排版
- linux常用操作命令
- 剑指offer之和为S的连续正数序列
- 最长上升连续子序列-LintCode
- 算法1.1.27
- DL0-DL tips
- leetcode 368. Largest Divisible Subset 类似LISS最长递增子序列问题 + DP动态规划
- ***股票自动交易软件AutoStock使用说明***
- Java-Classloader-loadeClass(String,boolean)、findClass(String)类加载源码解析
- 请求分页存储管理方式
- 梯度下降(Gradient Descent)小结
- Cannot change version of project facet Dynamic web module to 2.5