Skip to content

Commit fd1f2f9

Browse files
committed
maximum sumarry solved
1 parent 756ef83 commit fd1f2f9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

maximum-subarray/sora0319.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public int maxSubArray(int[] nums) {
3+
int n = nums.length;
4+
int[] dp = new int[n];
5+
6+
dp[0] = nums[0];
7+
int maxSum = dp[0];
8+
9+
for (int i = 1; i < n; i++) {
10+
dp[i] = Math.max(nums[i], dp[i - 1] + nums[i]);
11+
maxSum = Math.max(maxSum, dp[i]); // 최대값 갱신
12+
}
13+
14+
return maxSum;
15+
}
16+
17+
}
18+

0 commit comments

Comments
 (0)