Last active
December 25, 2015 05:48
-
-
Save Altimor/6926654 to your computer and use it in GitHub Desktop.
Biggest sum of consecutive NSNumbers in an NSArray
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
- (int) biggestSum:(NSArray*)array{ | |
int final = 0; | |
int tempfinal = 0; | |
for(int i = 0; i < array.count; i++){ | |
tempfinal = MAX(tempfinal+[((NSNumber*)array[i]) intValue],0); | |
final = MAX(final,tempfinal); | |
} | |
return final; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment