1221. Split a String in Balanced Strings Easy
1/**
2 * [1221] Split a String in Balanced Strings
3 *
4 * Balanced strings are those that have an equal quantity of 'L' and 'R' characters.
5 * Given a balanced string s, split it into some number of substrings such that:
6 *
7 * Each substring is balanced.
8 *
9 * Return the maximum number of balanced strings you can obtain.
10 *
11 * Example 1:
12 *
13 * Input: s = "RLRRLLRLRL"
14 * Output: 4
15 * Explanation: s can be split into "RL", "RRLL", "RL", "RL", each substring contains same number of 'L' and 'R'.
16 *
17 * Example 2:
18 *
19 * Input: s = "RLRRRLLRLL"
20 * Output: 2
21 * Explanation: s can be split into "RL", "RRRLLRLL", each substring contains same number of 'L' and 'R'.
22 * Note that s cannot be split into "RL", "RR", "RL", "LR", "LL", because the 2^nd and 5^th substrings are not balanced.
23 * Example 3:
24 *
25 * Input: s = "LLLLRRRR"
26 * Output: 1
27 * Explanation: s can be split into "LLLLRRRR".
28 *
29 *
30 * Constraints:
31 *
32 * 2 <= s.length <= 1000
33 * s[i] is either 'L' or 'R'.
34 * s is a balanced string.
35 *
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/split-a-string-in-balanced-strings/
40// discuss: https://leetcode.com/problems/split-a-string-in-balanced-strings/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45 pub fn balanced_string_split(s: String) -> i32 {
46 0
47 }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_1221() {
58 }
59}
60
Back
© 2025 bowen.ge All Rights Reserved.