Skip to content

Commit 2d67021

Browse files
committed
feat: maximum subarray
1 parent be8f4db commit 2d67021

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

maximum-subarray/minji-go.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Problem: https://leetcode.com/problems/maximum-subarray/
3+
Description: return the largest sum of the subarray, contiguous non-empty sequence of elements within an array.
4+
Concept: Array, Divide and Conquer, Dynamic Programming
5+
Time Complexity: O(N), Runtime 1ms
6+
Space Complexity: O(1), Memory 57.02MB
7+
*/
8+
class Solution {
9+
public int maxSubArray(int[] nums) {
10+
int max = nums[0];
11+
int sum = nums[0];
12+
for(int i=1; i<nums.length; i++){
13+
sum = Math.max(nums[i], nums[i]+sum);
14+
max = Math.max(max, sum);
15+
}
16+
return max;
17+
}
18+
}

0 commit comments

Comments
 (0)