(1,9,2,5,7,3,4,6,8,0)中最长的递增子序列为(3,4,6,8)。
滑动窗口 双指针的思路
import java.util.*;
// 1:无需package
// 2: 类名必须Main, 不可修改
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] arr = new int[]{1,9,2,5,7,3,4,6,8,0};
int p = 0,n;
int i = 0,j = 0,max = Integer.MIN_VALUE;
for(n =1;n<arr.length;n++){
if(arr[n]<arr[n-1]){
//System.out.println(p+" "+n);
int num = n-p;
if(max<num){
i = p; j = n;
max = num;
}
p = n;
}
}
int num = n-p;
if(max<num){
i = p; j = n;
max = num;
}
for(int k = i;k<j;k++){
System.out.print(arr[k]+" ");
}
}
}