My 1ms solution for Maximum Subarray


  • 2
    B
    public int maxSubArray(int[] nums) {
    		int length = nums.length;
    		int max =Integer.MIN_VALUE;
    		int tmp=0;
    		for(int i=0;i<length;i++){
    			tmp+=nums[i];
    			if (tmp>max) {
    				max=tmp;
    			}
    			if (tmp<0) {
    				tmp=0;
    			}
    		}
    		return max;
    	}

Log in to reply
 

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