Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def maxSubArray(self, nums: List[int]) -> int:
- l = len(nums)
- arr = [0]*(l+1)
- min_i = 0
- max_i = 0
- miny = arr[0]
- maxy = arr[0]
- for i in range(1,l+1):
- arr[i] = arr[i-1]+ nums[i-1]
- if(arr[i] >= maxy):
- print(maxy," Max")
- max_i = i - 1
- maxy = arr[i]
- if(arr[i] <= miny):
- print(miny," Min")
- min_i = i - 1
- miny = arr[i]
- print(arr)
- if(maxy <= 0):
- return max(nums)
- if(min_i < max_i):
- return maxy - miny
- else:
- return maxy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement