We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2646492 commit bc61f75Copy full SHA for bc61f75
maximum-subarray/toychip.java
@@ -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