-
Notifications
You must be signed in to change notification settings - Fork 161
/
split-a-string-in-balanced-strings.md
46 lines (34 loc) · 1.59 KB
/
split-a-string-in-balanced-strings.md
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
<p><i data-stringify-type="italic">Balanced</i> strings are those who have equal quantity of 'L' and 'R' characters.</p>
<p>Given a balanced string <code data-stringify-type="code">s</code> split it in the maximum amount of balanced strings.</p>
<p>Return the maximum amount of splitted balanced strings.</p>
<p> </p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "RLRRLLRLRL"
<strong>Output:</strong> 4
<strong>Explanation: </strong>s can be split into "RL", "RRLL", "RL", "RL", each substring contains same number of 'L' and 'R'.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> s = "RLLLLRRRLR"
<strong>Output:</strong> 3
<strong>Explanation: </strong>s can be split into "RL", "LLLRRR", "LR", each substring contains same number of 'L' and 'R'.
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> s = "LLLLRRRR"
<strong>Output:</strong> 1
<strong>Explanation: </strong>s can be split into "LLLLRRRR".
</pre>
<p><strong>Example 4:</strong></p>
<pre>
<strong>Input:</strong> s = "RLRRRLLRLL"
<strong>Output:</strong> 2
<strong>Explanation: </strong>s can be split into "RL", "RRRLLRLL", since each substring contains an equal number of 'L' and 'R'
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 1000</code></li>
<li><code>s[i] = 'L' or 'R'</code></li>
</ul>