12345678910111213141516171819202122232425262728293031 |
- package com.loveCoding.homework.j20250517;
- /**
- * @author WanJl
- * @version 1.0
- * @title T10
- * @description
- * **10. 统计最长连续递增序列**
- * 要求:找出数组中最长的连续递增子数组长度
- * 示例输入:`{1,3,5,4,7,8,9}`
- * 示例输出:4(对应子数组7,8,9或4,7,8,9)
- * @create 2025/5/24
- */
- public class T10 {
- public static void main(String[] args) {
- int[] arr={1,3,5,6,7,1,2,3,4,7,8,9,4,7,8,9};
- int t=1; //是临时记录序列长度,从1开始。
- int count=0; //记录最长的那个序列的长度,从0开始
- for (int i = 1; i < arr.length; i++) {
- if (arr[i]>arr[i-1]){
- t++;
- }else {
- if(t>count){
- count=t;
- }
- t=1;
- }
- }
- System.out.println(count);
- }
- }
|