Skip to content

Instantly share code, notes, and snippets.

@terakilobyte
Created November 17, 2018 02:11
Show Gist options
  • Save terakilobyte/5c0cf565f68731b9a6b42eaf5119988c to your computer and use it in GitHub Desktop.
Save terakilobyte/5c0cf565f68731b9a6b42eaf5119988c to your computer and use it in GitHub Desktop.
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