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 b7232f6 commit 0ce6c82Copy full SHA for 0ce6c82
maximum-subarray/changhyumm.py
@@ -0,0 +1,14 @@
1
+class Solution:
2
+ def maxSubArray(self, nums: List[int]) -> int:
3
+ max_total = nums[0]
4
+ total = 0
5
+ # subarray는 array에서 서로 인접해야함
6
+ # 인접한 값의 합이 마이너스인 경우, 그냥 현재 값만 사용하는게 합보다 큼
7
+ # total 이 0보다 작은경우 그냥 0으로 변경
8
+ for num in nums:
9
+ if total < 0:
10
11
+ total += num
12
+ max_total = max(total, max_total)
13
+ # 시간복잡도 O(n), 공간복잡도 O(1)
14
+ return max_total
0 commit comments