最长上升连续子序列
来源:互联网 发布:java运行环境官网下载 编辑:程序博客网 时间:2024/05/20 08:24
给定一个整数数组(下标从 0 到 n-1, n 表示整个数组的规模),请找出该数组中的最长上升连续子序列。(最长上升连续子序列可以定义为从右到左或从左到右的序列。)
注意事项
time
样例
给定 [5, 4, 2, 1, 3], 其最长上升连续子序列(LICS)为 [5, 4, 2, 1], 返回 4.
注意事项
time
样例
给定 [5, 4, 2, 1, 3], 其最长上升连续子序列(LICS)为 [5, 4, 2, 1], 返回 4.
给定 [5, 1, 2, 3, 4], 其最长上升连续子序列(LICS)为 [1, 2, 3, 4], 返回 4.
import java.util.Scanner;/** * 给定一个整数数组(下标从 0 到 n-1, n 表示整个数组的规模),请找出该数组中的最长上升连续子序列。(最长上升连续子序列可以定义为从右到左或从左到右的序列。) 注意事项time样例给定 [5, 4, 2, 1, 3], 其最长上升连续子序列(LICS)为 [5, 4, 2, 1], 返回 4.给定 [5, 1, 2, 3, 4], 其最长上升连续子序列(LICS)为 [1, 2, 3, 4], 返回 4. * * @author Dell * */public class Test397 { public static int longestIncreasingContinuousSubsequence(int[] A) { if(A.length==0) return 0; int maxLength=1; int maxlength1=1; int count=1; int count1=1; for(int i=0;i<A.length-1;i++) { if(A[i+1]<A[i]) { count++; } else { if(count>maxLength) { maxLength=count; } count=1; } if(A[i+1]>A[i]) { count1++; } else { if(count1>maxLength) { maxLength=count1; } count1=1; } } if(count>maxLength) { maxLength=count; } if(count1>maxLength) { maxLength=count1; } return maxLength; }public static void main(String[] args) {Scanner sc=new Scanner(System.in);int n=sc.nextInt();int[] a=new int[n];for(int i=0;i<a.length;i++){a[i]=sc.nextInt();} System.out.println(longestIncreasingContinuousSubsequence(a));}}
阅读全文
0 0
- 最长上升连续子序列
- 最长上升连续子序列
- 最长连续上升子序列
- 最长上升连续子序列
- 最长上升连续子序列
- 最长上升连续子序列
- 最长上升连续子序列
- 最长上升连续子序列
- 最长上升连续子序列
- 最长上升连续子序列
- hdu1069-最长连续上升子序列
- 题目:最长上升连续子序列
- LintCode--最长上升连续子序列
- lintcode-最长上升连续子序列-397
- 最长上升连续子序列(LintCode)
- LintCode- 最长上升连续子序列
- lintCode刷题--最长上升连续子序列
- 最长上升连续子序列 II
- StringBoot + String定时器
- 惊心动魄!程序员们说这些时刻再也不想经历了
- JAVA中clob字段变成String
- extends和implements区别
- 安卓自定义view进阶(1)
- 最长上升连续子序列
- 四元数的基本运算
- 安装JDK+tomcat+jenkins
- BFS:CF356C-Compartments
- safari 浏览器window.history.go(-1)运行无效解决办法
- 网卡驱动程序igb ixgbe 介绍
- 作业
- PAT (Advanced Level) Practise 1088 Rational Arithmetic (20)
- 贵在坚持