T10.java 886 B

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