Java easy and clean solution 16 ms 53% O(n)


  • 0
    public class Solution {
        public int maxSubArray(int[] nums) {
            if(nums==null||nums.length<1)return 0;
            int temp = nums[0];
            int max = temp;
            for(int i = 1 ; i < nums.length ; i++){
                temp = temp < 0 ? nums[i] : (temp+=nums[i]);
                if(temp > max)max = temp;
            }
            return max;
        }
    }
    

Log in to reply
 

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