Skip to content

Instantly share code, notes, and snippets.

@Altimor
Last active December 25, 2015 05:48
Show Gist options
  • Save Altimor/6926654 to your computer and use it in GitHub Desktop.
Save Altimor/6926654 to your computer and use it in GitHub Desktop.
Biggest sum of consecutive NSNumbers in an NSArray
- (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