【问题描述】
在数列 a[1], a[2], ..., a[n] 中,如果 a[i] < a[i+1] < a[i+2] <
... < a[j],则称 a[i] 至 a[j] 为一段递增序列,长度为 j-i+1。
给定一个数列,请问数列中最长的递增序列有多长。
【输入格式】
输入的第一行包含一个整数 n。
第二行包含 n 个整数 a[1], a[2], ..., a[n],相邻的整数间用空格分隔,表示给定的数列。
【输出格式】
输出一行包含一个整数,表示答案。
【样例输入】
7
5 2 4 1 3 7 2
【样例输出】
3
【评测用例规模与约定】
对于 50% 的评测用例,2 <= n <= 100,0 <= 数列中的数 <= 1000。
对于所有评测用例,2 <= n <= 1000,0 <= 数列中的数 <= 10000。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = sc.nextInt();
}
int res = 0;
int cnt = 1;
for (int i = 0; i < nums.length - 1; i++) {
if (nums[i + 1] > nums[i]) {
cnt++;
} else {
cnt = 1;
}
res=Math.max(cnt, res);
}
System.out.println(res);
sc.close();
}
}