Skip to content

Commit

Permalink
feat: week3 medium 문제풀이(maximum-subarray)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinah92 committed Dec 27, 2024
1 parent c184b94 commit 93fe9c3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions maximum-subarray/jinah92.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
num_set = {}
result = -math.inf

for idx, num in enumerate(nums):
if idx == 0:
num_set[idx] = max(nums[0], result)
else:
num_set[idx] = max(num, num_set[idx-1] + num)
tmp_sum = num_set[idx]
result = max(result, tmp_sum)

return result

0 comments on commit 93fe9c3

Please sign in to comment.