-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathletcode_1221.py
More file actions
57 lines (42 loc) · 1.07 KB
/
letcode_1221.py
File metadata and controls
57 lines (42 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Balanced strings are those that have an equal quantity of 'L' and 'R' characters.
# Given a balanced string s, split it in the maximum amount of balanced strings.
# Return the maximum amount of split balanced strings.
# Example 1:
# Input: s = "RLRRLLRLRL"
# Output: 4
# Explanation: s can be split into "RL", "RRLL", "RL", "RL", each substring contains same number
# of 'L' and 'R'.
# Example 2:
# Input: s = "RLLLLRRRLR"
# Output: 3
# Explanation: s can be split into "RL", "LLLRRR", "LR", each substring contains same number
# of 'L' and 'R'.
s = "RLLLLRRRLR"
cont = 0
cont2= 0
output = 0
for i in s:
if i == 'R':
cont += 1
if cont == cont2:
output +=1
cont2 = 0
cont = 0
elif i == 'L':
cont2 += 1
if cont == cont2:
output +=1
cont2 = 0
cont = 0
print(output)
# solucion 2
# count = 0
# total = 0
# for i in s:
# if i == 'L':
# count += 1
# else:
# count -= 1
# if count == 0:
# total += 1
# print(total)