当前位置:网站首页>P7 Alibaba Interview Questions 2020.07 Sliding Window Algorithm (Alibaba Cloud Interview)

P7 Alibaba Interview Questions 2020.07 Sliding Window Algorithm (Alibaba Cloud Interview)

2022-08-09 06:33:00 In the history of the strongest disciple

The problem is that the numbers in a data may be positive and negative integers. Find the maximum value of the sum of n consecutive numbers.

In fact, it is the maximum value in the double pointer sliding recording cycle.

Implementation:

import java.math.BigDecimal;public class Test9 {/*public double test(Double x,int flage){double returnData = 0.0;double x1 = 0;double x2 = x;double point = ;while(new BigDecimal(x).)return returnData;}*//*public int test(int[] arr){int maxtotal = 0;for(int i = 0;isumTotalMax){sumTotalMax = sumTotal+arr[j];}sumTotal=sumTotal+arr[j];}if(sumTotalMax>maxtotal){maxtotal = sumTotalMax;}}return maxtotal;}*/public int test(int[] arr){int maxtotal = 0;for(int i = 0;isumTotalMax){sumTotalMax = sumTotal+arr[j];}sumTotal=sumTotal+arr[j];}if(sumTotalMax>maxtotal){maxtotal = sumTotalMax;}}return maxtotal;}public static void main(String[] args) {Test9 test9 = new Test9();int[] arr = {-2,11,-4,13,-5,2};System.out.println(test9.test(arr));}}

原网站

版权声明
本文为[In the history of the strongest disciple]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208090629203783.html