diff --git a/apps/docs/content/(05-decision-space)/greedy/53-maximum-subarray.mdx b/apps/docs/content/(05-decision-space)/greedy/53-maximum-subarray.mdx index cb6649a..098bc44 100644 --- a/apps/docs/content/(05-decision-space)/greedy/53-maximum-subarray.mdx +++ b/apps/docs/content/(05-decision-space)/greedy/53-maximum-subarray.mdx @@ -40,4 +40,14 @@ If you have figured out the O(n) solution, try coding another solution using the ```py class Solution: def maxSubArray(self, nums: list[int]) -> int: + best, total = nums[0], nums[0] + + for i in range(1, len(nums)): + if total < 0: + total = nums[i] + else: + total = total + nums[i] + best = max(best, total) + + return best ```