Skip to content

Commit 15bcd79

Browse files
committed
Time: 1 ms (100.00%), Space: 73 MB (76.92%) - LeetHub
1 parent 766b18c commit 15bcd79

File tree

1 file changed

+16
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)