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 c787f33 commit 778ae3eCopy full SHA for 778ae3e
maximum-subarray/gwbaik9717.js
@@ -0,0 +1,18 @@
1
+// Time complexity: O(n)
2
+// Space complexity: O(n)
3
+
4
+/**
5
+ * @param {number[]} nums
6
+ * @return {number}
7
+ */
8
+var maxSubArray = function (nums) {
9
+ const n = nums.length;
10
+ const dp = Array.from({ length: n + 1 }, () => Number.MIN_SAFE_INTEGER);
11
+ dp[0] = 0;
12
13
+ for (let i = 1; i <= n; i++) {
14
+ dp[i] = Math.max(dp[i - 1] + nums[i - 1], nums[i - 1]);
15
+ }
16
17
+ return Math.max(...dp.slice(1));
18
+};
0 commit comments