Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. # Complete the countingValleys function below.
  2. def countingValleys(n, s):
  3.     tot_valley = 0    
  4.     current_level = 0
  5.  
  6.     hike = list(s)
  7.     for cur_step in hike:
  8.         if cur_step == 'U':
  9.             current_level += 1
  10.         elif cur_step == 'D':
  11.             if current_level == 0:
  12.                 tot_valley += 1
  13.             current_level -= 1
  14.     return tot_valley
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement