package datasSouce;
//返回一个递增的且连续的最长的子数组长度
public class MaxSeq {
public static void main(String[] args) {
System.out.println(findLength(new int[]{1,2,3,2,3,4,3,4,5,6,7}));
}
public static int findLength(int[] nums){
int start = 0;
int max =0;
for (int i = 1; i < nums.length; i++){
if (nums[i] <= nums[i-1]){
//当下一个大于上一个时把i赋值给start
start = i;
}
//每次中止的长度为: i-start+1
max = Math.max(max, (i - start + 1));
}
return max;
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)