Created
November 30, 2017 23:01
-
-
Save Pierian-Data/51202d7a84e36537df97a7c9ca78061f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def large_cont_sum(arr): | |
# Check to see if array is length 0 | |
if len(arr)==0: | |
return 0 | |
# Start the max and current sum at the first element | |
max_sum=current_sum=arr[0] | |
# For every element in array | |
for num in arr[1:]: | |
# Set current sum as the higher of the two | |
current_sum=max(current_sum+num, num) | |
# Set max as the higher between the currentSum and the current max | |
max_sum=max(current_sum, max_sum) | |
return max_sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Sreeja123ut , @Liulinya
Nope.
Try other examples:
The result should look like: