Find the maximum interval sum in a list of real numbers

后端 未结 9 1371
长情又很酷
长情又很酷 2020-12-10 17:20

Here\'s an interview questions that a colleague asked for a programming position. I thought this was great for watching the interviewee think it through. I\'d love to get re

9条回答
  •  半阙折子戏
    2020-12-10 18:11

    Try this code .. it would work fine for at least one +ve number in the array.. O(n) just one for loop used..

    public static void main(String[] args) {
        int length ;
        int a[]={-12, 14, 0, -4, 61, -39};  
        length=a.length;
    
        int absoluteMax=0, localMax=0, startIndex=0, lastIndex=0, tempStartIndex=0;
        for (int index=0;index

提交回复
热议问题