class Solution {
public:
int balancedStringSplit(string s) {
int fast = 0;
int n = 0;
int sum = 0;
while(fast < s.size())
{
if(s[fast] == 'R')
{
n += 1;
}
else
{
n -= 1;
}
if(n==0)
{
sum += 1;
}
fast++;
}
return sum;
}
};
leetcode每日一题第109天
最新推荐文章于 2024-08-21 10:11:50 发布