#53
Maximum Subarray
medium· Greedyruns: 0Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.
sign in to paste and practice your own solution
wpm 0acc 100%time 0:000 / 233
class Solution:
def maxSubArray(self, nums: list[int]) -> int:
best = current = nums[0]
for num in nums[1:]:
current = max(num, current + num)
best = max(best, current)
return best
click the box to focus · tab inserts 4 spaces · backspace to correct · esc to pause
desktop only
codedrill is a typing game and needs a real keyboard. open this on a laptop or desktop to practice.
you can still browse problems and sections from your phone.