LintCode刷题——最长上升连续子序列
来源:互联网 发布:互联网职位 知乎 编辑:程序博客网 时间:2024/06/06 02:40
问题描述:
给定一个整数数组(下标从 0 到 n-1, n 表示整个数组的规模),请找出该数组中的最长上升连续子序列。(最长上升连续子序列可以定义为从右到左或从左到右的序列。)
样例:
给定 [5, 4, 2, 1, 3]
, 其最长上升连续子序列(LICS)为 [5, 4, 2, 1]
, 返回 4
.
给定 [5, 1, 2, 3, 4]
, 其最长上升连续子序列(LICS)为 [1, 2, 3, 4]
, 返回 4
.
解决:
public class Solution { /* * @param : An array of Integer * @return: an integer */ public int longestIncreasingContinuousSubsequence(int[] array) { if(array.length==0){ return 0; } int increasingResult=1;int unicreasingResult=1;int currentIncreasingResult=1;int currentUnicreasingResult=1;for(int i=1;i<array.length;i++) { //最长连续递增if(array[i]>array[i-1]) {currentIncreasingResult++;}else {currentIncreasingResult=1;}increasingResult=Integer.max(increasingResult, currentIncreasingResult); //最长连续递减 if(array[i]<array[i-1]) {currentUnicreasingResult++;}else {currentUnicreasingResult=1;}unicreasingResult=Integer.max(unicreasingResult, currentUnicreasingResult);}return unicreasingResult>increasingResult?unicreasingResult:increasingResult; }}
阅读全文
0 0
- LintCode刷题——最长上升连续子序列
- lintCode刷题--最长上升连续子序列
- lintcode——最长上升连续子序列
- LintCode--最长上升连续子序列
- lintcode-最长上升连续子序列-397
- 最长上升连续子序列(LintCode)
- LintCode- 最长上升连续子序列
- LintCode:最长上升连续子序列
- lintcode -- 最长上升连续子序列
- lintcode:最长上升连续子序列
- LintCode: 最长上升连续子序列
- Lintcode最长上升连续子序列
- 最长上升连续子序列-LintCode
- 最长上升连续子序列-LintCode
- LintCode 最长上升连续子序列
- lintcode longest-increasing-continuous-subsequence 最长上升连续子序列
- LintCode(easy)最长上升连续子序列
- [Lintcode 397] 最长上升连续子序列(Python)
- springboot vue 安装 每天进步百分之一
- cannot be read or is not a valid ZIP file
- Linux学习——Linux常用命令-文件处理命令
- XSHELL工具上传文件到Linux以及下载文件到本地(Windows)
- spring boot 部署
- LintCode刷题——最长上升连续子序列
- code profiling
- poj_2752_kmp_nxt_application_求s 所有子串是s的前缀又是后缀的长度
- caffe中用faster-rcnn训练自己的数据集中出现的各种问题总结
- scrapy学习
- 检验样本是否服从正态分布,处理偏态分布
- Hibernate(2)
- 必须要见识
- 活动记录