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 5c2fc91 commit 557ca27Copy full SHA for 557ca27
โmaximum-subarray/YuuuuuuYu.javaโ
@@ -0,0 +1,24 @@
1
+/**
2
+ * Runtime: 1ms
3
+ * Time Complexity: O(n)
4
+ *
5
+ * Memory: 76.88MB
6
+ * Space Complexity: O(1)
7
8
+ * Approach: ์นด๋ฐ์ธ ์๊ณ ๋ฆฌ์ฆ
9
+ * - ๋ถ๋ถ ๋ฐฐ์ด์ ํฉ์ด ์ต๋๊ฐ ๋๋ ๊ฐ์ ์ฐพ๋ ์๊ณ ๋ฆฌ์ฆ
10
+ * 1) ์ด์ ํฉ๋ณด๋ค ํ์ฌ ์ซ์๊ฐ ๋ ํฌ๋ฉด ํ์ฌ ์ซ์๋ก sum์ ์ด๊ธฐํ
11
+ */
12
+class Solution {
13
+ public int maxSubArray(int[] nums) {
14
+ int sum = nums[0];
15
+ int max = nums[0];
16
+
17
+ for (int i=1; i<nums.length; i++) {
18
+ sum = Math.max(nums[i], sum+nums[i]);
19
+ max = Math.max(max, sum);
20
+ }
21
22
+ return max;
23
24
+}
0 commit comments