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 27250dd commit c5efe09Copy full SHA for c5efe09
53-maximum-subarray.js
@@ -14,6 +14,23 @@ const maxSubArray = function(nums) {
14
15
// another
16
17
+/**
18
+ * @param {number[]} nums
19
+ * @return {number}
20
+ */
21
+const maxSubArray = function(nums) {
22
+ const n = nums.length, dp = Array(n).fill(0)
23
+ dp[0] = nums[0]
24
+ let res = dp[0]
25
+ for(let i = 1; i < n; i++) {
26
+ dp[i] = Math.max(dp[i - 1], 0) + nums[i]
27
+ res = Math.max(res, dp[i])
28
+ }
29
+ return res
30
+};
31
+
32
+// another
33
34
/**
35
* @param {number[]} nums
36
* @return {number}
0 commit comments