原题题目
代码实现(首刷自解)
class Solution {
public:int balancedStringSplit(string s) {
int ret = 0,l = 0,r = 0;for(const auto& chr:s){
if(chr == 'R') ++r;else ++l;if(l == r){
++ret;l = r = 0;}}return ret;}
};
class Solution {
public:int balancedStringSplit(string s) {
int ret = 0,l = 0,r = 0;for(const auto& chr:s){
if(chr == 'R') ++r;else ++l;if(l == r){
++ret;l = r = 0;}}return ret;}
};