思路:
// @Title: 分割平衡字符串 (Split a String in Balanced Strings)
// @Author: qisiii
// @Date: 2024-05-13 19:03:04
// @Runtime: 0 ms
// @Memory: 40.3 MB
// @comment:
// @flag:
class Solution {
public int balancedStringSplit(String s) {
int count = 0, cha = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'R') {
cha++;
} else {
cha--;
}
if (cha == 0) {
count++;
}
}
return count;
}
}