分割平衡字符串 (Split a String in Balanced Strings)

 

思路:

// @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;
    }
}
Licensed under CC BY-NC-SA 4.0
最后更新于 2024-10-18