Advertisement
arvind_iyer_2001

Untitled

Jun 22nd, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. def maxSubArray(self, nums: List[int]) -> int:
  2.     l = len(nums)
  3.     arr = [0]*(l+1)
  4.     min_i = 0
  5.     max_i = 0
  6.     miny = arr[0]
  7.     maxy = arr[0]
  8.     for i in range(1,l+1):
  9.            
  10.         arr[i] = arr[i-1]+ nums[i-1]
  11.         if(arr[i] >= maxy):
  12.             print(maxy," Max")
  13.             max_i = i - 1
  14.             maxy = arr[i]
  15.         if(arr[i] <= miny):
  16.             print(miny," Min")
  17.             min_i = i - 1
  18.             miny = arr[i]
  19.     print(arr)
  20.     if(maxy <= 0):
  21.         return max(nums)
  22.     if(min_i < max_i):
  23.         return maxy - miny
  24.     else:
  25.         return maxy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement