Created
April 11, 2022 21:42
-
-
Save aaronshaver/18e55f92fa3e1e04f2966082adf78c30 to your computer and use it in GitHub Desktop.
IterTools accumulate
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
# this is the classic "return highest altitude" of hill climbing problem | |
from itertools import accumulate | |
def largestAltitude(self, A): | |
return max(0, max(accumulate(A))) | |
# the reason for the "0, " is because of data sets like [-4,-3,-2,-1,4,3,2] | |
# where the accumulated addition of those values is -1, yet starting altitude is 0, | |
# which is higher |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment