GoConqr has a new look! Let us know what you think.

Flashcards

Max Subarray

Suhas S English 1 card

Cards in this deck (1)

  1. 1Input: [-2,1,-3,4,-1,2,1,-5,4], Output: 6 Explanation: [4,-1,2,1] has the largest sum = 6.public int maxSubArray(int[] nums) {
    if(nums == null || nums.length ==0)
    return 0;
    int result = Integer.MIN_VALUE;
    int runSum = 0;
    for(int i=0; i< nums.length; i++){
    runSum = nums[i]>runSum+nums[i] ? nums[i] : runSum+nums[i];
    result = Math.max(result, runSum);
    }
    return result;
    }

Information

Description
Flashcards on Max Subarray, created by Suhas S on 27/05/2018.
Created by
Suhas S
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?