Skip to content

Commit b101fa3

Browse files
committed
Time: 2 ms (66.09%), Space: 73.6 MB (60.38%) - LeetHub
1 parent 03047b1 commit b101fa3

File tree

1 file changed

+14
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)