Skip to content

Commit ffbcf9a

Browse files
committed
feat: maximum-subarray
1 parent bd7c413 commit ffbcf9a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

maximum-subarray/HodaeSsi.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# 시간복잡도 : O(N)
2+
# 공간복잡도 : O(1)
3+
class Solution:
4+
def maxSubArray(self, nums: List[int]) -> int:
5+
global_sum = nums[0]
6+
local_sum = nums[0]
7+
8+
for i in range(1, len(nums)):
9+
local_sum = max(nums[i], local_sum + nums[i])
10+
global_sum = max(local_sum, global_sum)
11+
12+
return global_sum
13+

0 commit comments

Comments
 (0)