Files
leetcode-master/problems/1221.分割平衡字符串.md
youngyangyang04 8b640430de Update
2020-11-27 09:40:03 +08:00

401 B
Raw Blame History

这是贪心啊LRLR 这本身就是平衡子串 , 但要LR这么分割这是贪心

class Solution {
public:
    int balancedStringSplit(string s) {
        int result = 0;
        int count = 0;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == 'R') count++;
            else count--;
            if (count == 0) result++;
        }
        return result;
    }
};