最长连续子序列
来源:互联网 发布:遭遇网络诈骗怎么报警 编辑:程序博客网 时间:2024/05/22 12:44
使用和相邻的进行比较,记录
package cn.liu.test3;
public class Main{
public static void main(String[] args) {
int[] nums = {1,7,7,8,3,6,7,2};
int res = longSubSequence(nums);
System.out.println(res);
}
public static int longSubSequence(int[] nums) {
if(nums.length <= 0)
return 0;
int res = 1;
int cnt1 = 1, cnt2 = 1;
for(int i = 1; i < nums.length; i++){
if(nums[i] > nums[i-1]){
cnt1 ++;
res = Math.max(cnt1, res);
cnt2 = 1;
} else{
cnt2 ++;
res = Math.max(cnt2, res);
cnt1 = 1;
}
}
return res;
}
}
public class Main{
public static void main(String[] args) {
int[] nums = {1,7,7,8,3,6,7,2};
int res = longSubSequence(nums);
System.out.println(res);
}
public static int longSubSequence(int[] nums) {
if(nums.length <= 0)
return 0;
int res = 1;
int cnt1 = 1, cnt2 = 1;
for(int i = 1; i < nums.length; i++){
if(nums[i] > nums[i-1]){
cnt1 ++;
res = Math.max(cnt1, res);
cnt2 = 1;
} else{
cnt2 ++;
res = Math.max(cnt2, res);
cnt1 = 1;
}
}
return res;
}
}
阅读全文
0 0
- 连续最长子序列
- 最长连续子序列
- 最长连续子序列
- 最长连续子序列
- fjnu 最长连续子序列
- 最长连续子序列 DP
- 最长连续公共子序列
- 最长连续子序列和
- 最长连续公共子序列
- 最长上升连续子序列
- lintcode-最长连续子序列
- FZU2216 最长连续子序列
- 最长公共子序列(连续)
- 最长连续递增子序列
- 最长上升连续子序列
- 最长连续上升子序列
- 最长连续递增子序列
- 最长上升连续子序列
- Ubuntu下PX4飞控开发环境搭建
- 之前用的一个多进程python爬虫
- myeclispe调试Fn键
- [转]详细解释CNN卷积神经网络各层的参数和链接个数的计算
- 苹果手机用H5audio标签无法自动播放音乐处理方法
- 最长连续子序列
- Java中Synchronized的用法
- 单片机mcu—time定时器详解
- Java设计模式之行为型模式(一)
- 特殊字符显示问题
- mybatis-generator生成逆向工程两种方式
- NGINX location 匹配顺序
- HDU 6180 Schedule(任务调度 贪心策略 17多校第十场)
- 手游开发分辨率