Skip to content

Commit 4a2c349

Browse files
committed
Maximum Subarray solution
1 parent f71ccbf commit 4a2c349

File tree

1 file changed

+15
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)