最长连续递增子序列
程序员文章站
2024-03-14 20:50:41
...
/**
* 最长连续递增子序列(部分有序)
* @author 田秀彪
* (1,9,2,5,7,3,4,6,8,0)中最长的递增子序列为(3,4,6,8)。
*/
public class Case04_最长连续递增子序列 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] arr = { 1, 9, 2, 5, 7, 3, 4, 6, 8, 9, 0 };
MaxLengthXulie(arr);
}
public static void MaxLengthXulie(int[] arr) {
int max = 0, count = 0;
int left = 0, right = 0, flagstar = 0;
for (int i = 0; i < arr.length - 1; i++) {
right = i + 1;
if (arr[i + 1] > arr[i]) {
count++;
if (count > max) {
max = count;
flagstar = left;
}
} else {
count = 0;
left = right;
}
}
for (int i = flagstar; i <= flagstar + max; i++) {
System.out.print(arr[i] + " ");
}
}
}