SHARE
TWEET

Untitled

a guest Jul 20th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def max_sub(arr):
  2.     max_val = 0
  3.     summ = 0
  4.     for i in range(len(arr)):
  5.         summ += arr[i]
  6.         if i == 0:
  7.             max_val = summ
  8.         elif summ < arr[i]:
  9.             summ = arr[i]
  10.             if arr[i] > max_val:
  11.                 max_val = arr[i]
  12.         elif summ > max_val:
  13.             max_val = summ
  14.  
  15.     return max_val
  16.  
  17.  
  18. arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
  19. # print(max_sub(arr))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top