When I submit my code it keeps telling me wrong answer. But I run the same input in my laptop, I get the right answer


  • 0
    K
    int max=A[0], i=0;
        while (A[i]<=0 && i<n) {
            
            if (A[i]>max) max=A[i];
            ++i;
            
        }
        if (i==n) return max;
        int b=0, maxsum=0;
        while (b<n ) {
            int i=b, sum=0, runningsum=0;
            while (A[i]<=0 && i<n) ++i;
            b=i;
            int  e=b;
            while (A[e]>0) {
                sum+=A[e];
                ++e;
            }
            i=e;
            runningsum=sum;
            while (runningsum>0 &&  i<n) {
                runningsum+=A[i];
                if (runningsum>sum) {
                    sum=runningsum;
                }
                ++i;
            }
            if (maxsum<sum) {
                maxsum=sum;
                
            }
            b=i;
        }
        return maxsum;

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.