Skip to content

Commit 3f5bbfb

Browse files
authored
Solution
1 parent ea163dc commit 3f5bbfb

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/python3
2+
3+
import math
4+
import os
5+
import random
6+
import re
7+
import sys
8+
9+
# Complete the countingValleys function below.
10+
def countingValleys(n, s):
11+
level=valley=0
12+
for i in range(n):
13+
if(s[i]=='U'):
14+
level+=1
15+
if(level==0):
16+
valley+=1
17+
else:
18+
level-=1
19+
20+
return valley
21+
22+
if __name__ == '__main__':
23+
fptr = open(os.environ['OUTPUT_PATH'], 'w')
24+
25+
n = int(input())
26+
27+
s = input()
28+
29+
result = countingValleys(n, s)
30+
31+
fptr.write(str(result) + '\n')
32+
33+
fptr.close()

0 commit comments

Comments
 (0)