O(n) Java Solution , esay to understand

  • 0
    public static int maxSubArray(int[] nums) {
        int res = nums[0];
        int sum = nums[0];
        for(int i = 1;i<nums.length; i++){
        		sum += nums[i];
        		sum = nums[i];
        	res = Math.max(res, sum);
        return res;

Log in to reply

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