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 25e7d6c commit 99460e3Copy full SHA for 99460e3
maximum-subarray/eunhwa99.java
@@ -1,15 +1,18 @@
1
-// 시간 복잡도: DP -> O(N)
2
-// 공간 복잡도: nums 배열 크기 - O(N)
3
+// 이전 솔루션과 동일
+// 시간 복잡도: O(n) - n은 주어진 배열의 길이
4
+// 공간 복잡도: O(1) - 상수 공간 사용
5
class Solution {
- public int maxSubArray(int[] nums) {
6
- int currentSum = nums[0];
7
- int maxSum = currentSum;
8
- for (int i = 1; i < nums.length; ++i) {
9
- currentSum = Math.max(currentSum + nums[i], nums[i]);
10
- maxSum = Math.max(maxSum, currentSum);
11
- }
12
-
13
- return maxSum;
+
+ public int maxSubArray(int[] nums) {
+ int currentSum = nums[0];
+ int maxSum = currentSum;
+ for (int i = 1; i < nums.length; ++i) {
+ currentSum = Math.max(currentSum + nums[i], nums[i]);
+ maxSum = Math.max(maxSum, currentSum);
14
}
15
+ return maxSum;
16
+ }
17
18
0 commit comments