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 d748504 commit 57cd633Copy full SHA for 57cd633
maximum-subarray/jeongwoo903.js
@@ -0,0 +1,21 @@
1
+/*
2
+* 시간 복잡도: O(n)
3
+* 공간 복잡도: O(1)
4
+*/
5
+
6
+/**
7
+ * @param {number[]} nums
8
+ * @return {number}
9
+ */
10
+var maxSubArray = function(nums) {
11
+ let max = nums[0];
12
+ let result = nums[0];
13
14
+ for (let index = 1; index < nums.length; index++) {
15
+ const num = nums[index];
16
+ result = Math.max(result + num, num);
17
+ max = Math.max(max, result);
18
+ }
19
20
+ return max;
21
+};
0 commit comments