Skip to content

Commit b448877

Browse files
committed
Add maxium-subarray solution - s0ooo0k
1 parent db63f49 commit b448877

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

maximum-subarray/Solution.java

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

0 commit comments

Comments
 (0)