//给定一个整数数组 nums ,找到一个具有最大和的连续子数组//(子数组最少包含一个元素),返回其最大和。//时间复杂度:O(n)publicclassMain{publicstaticvoidmain(String[] args){int[] a ={-2,1,-3,4,-1,2,1,-5,-4};
System.out.println(fun(a));}publicstaticintfun(int[] a){int res = a[0];int sum =0;for(int i=0;i<a.length;i++){if(sum>0){
sum = sum+a[i];}else{
sum = a[i];}
res = Math.max(res,sum);}return res;}}
classSolution{publicintjump(int[] nums){int n = nums.length;if(nums.length==1)return0;int step =0;int start =0;//起跳int end =0;//落点while(end<n-1){int nextReach = end;for(int i = start;i<=end;i++){
nextReach = Math.max(nextReach,nums[i]+i);}
start = end+1;
end = nextReach;
step++;}return step;}}