We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent be8f4db commit 2d67021Copy full SHA for 2d67021
maximum-subarray/minji-go.java
@@ -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