Last active
February 24, 2023 14:52
-
-
Save NicolaM94/7dc6773887badbb8d4563bf74fa544b0 to your computer and use it in GitHub Desktop.
Forward solution
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 forwardSolution (buildings): | |
haveSight = [buildings[0]] | |
for b in buildings[1:]: | |
if b > haveSight[0]: | |
haveSight = [b] | |
continue | |
if b > haveSight[-1]: | |
haveSight[-1] = b | |
else: | |
haveSight.append(b) | |
return haveSight |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment