Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

public int maxSubArray(int[] nums) { int res = nums[0], sum = nums[0]; for (int i = 1; i < nums.length; i++) { if (sum < 0 && sum < nums[i]) sum = nums[i]; else sum += nums[i]; if (sum > res) res = sum; } return res; }

if (sum < 0 && sum < nums[i]) sum = nums[i];

sum < nums[i] check seem like is redundant, with

if (sum > res) res = sum;

You mean you want to remove "sum < nums[i]"? It wouldn't work since 'sum' might be bigger than 'nums[i]', "sum = nums[i]" would make 'sum' smaller.

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