Created
November 17, 2018 02:11
-
-
Save terakilobyte/5c0cf565f68731b9a6b42eaf5119988c 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 count_valleys(s): | |
elevation = 0 | |
valleys = 0 | |
for i in s: | |
if i == "D": | |
elevation -= 1 | |
if elevation == -1: | |
valleys += 1 | |
else: | |
elevation += 1 | |
print(valleys) | |
count_valleys("DDUUDDUUUD") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment