Skip to content

Commit bc61f75

Browse files
committed
maximum-subarray solution
1 parent 2646492 commit bc61f75

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

maximum-subarray/toychip.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public int maxSubArray(int[] nums) {
3+
int maxSum = nums[0];
4+
int currentSum = nums[0];
5+
6+
for (int i = 1; i < nums.length; i++) {
7+
currentSum = Math.max(nums[i], currentSum + nums[i]);
8+
maxSum = Math.max(maxSum, currentSum);
9+
}
10+
return maxSum;
11+
}
12+
}

0 commit comments

Comments
 (0)