public static void main(String[] args) {
int[] num = {1,2,3,2,3,4,5,3,4,5,6,7};
System.out.println("最长连续递增的子序列为:" + findLength(num));
}
//贪心算法,获取数组中最长递增子序列
public static int findLength(int[] num) {
int start = 0;
int max = 0;
for (int i = 1; i < num.length; i++) {
if (num[i] <= num[i - 1]){
start = i;
}
max = Math.max(i - start + 1, max);
}
return max;
}
贪心算法,获取数组中最长递增子序列
于 2023-08-22 22:06:40 首次发布