标签:microsoft ges bsp 代码 连续 http 分享图片 pre inf
题目:(1,9,2,5,7,3,4,6,8,0,)中最长的递增子序列为(3,4,6,8)。
代码:
public class 最长递增子序列 {
public static void main(String[] args) {
int []arr = {1,0,2,5,7,3,4,6,8,9,1,2};
getLargestLen(arr);
}
private static void getLargestLen(int[] arr) {
int begin=0; // 最长递增子序列长度的开始位
int maxLen = 1; // 最长递增子序列长度
int k = 1; // 递增子序列长度
for (int end = 1; end < arr.length; end++) {
if(arr[end]>=arr[end-1]){
k++;
}else {
if (k>=maxLen) {
maxLen = k;
k=1;
begin = end-maxLen;
}
}
}
System.out.print("最长连续递增子序列为:");
for(int i = begin;i<begin+maxLen;i++)
System.out.print(arr[i] + " ");
}
}
结果:

标签:microsoft ges bsp 代码 连续 http 分享图片 pre inf
原文地址:https://www.cnblogs.com/xiaoyh/p/10262061.html