Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. import math
  2. class Solution:
  3.     def maxSubArray(self, nums: List[int]) -> int:
  4.         current_max = -math.inf
  5.         if len(nums) == 0:
  6.             return current_max
  7.  
  8.         current_sum = 0
  9.  
  10.         for i in range(0, len(nums)):
  11.             current_sum += nums[i]
  12.             current_max = max(current_sum, current_max)
  13.             if current_sum < 0:
  14.                 current_sum = 0
  15.  
  16.         return current_max
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement