---
# System prepended metadata

title: '[1221. Split a String in Balanced Strings](https://leetcode.com/problems/split-a-string-in-balanced-strings/)'

---

# [1221. Split a String in Balanced Strings](https://leetcode.com/problems/split-a-string-in-balanced-strings/)
![](https://i.imgur.com/th8oV6o.png)
![](https://i.imgur.com/Y9YjdrJ.png)


int balancedStringSplit(char * s){
    int charL=0;
    int charR=0;
    int sum=0;
    for(int i=0;i<strlen(s);i++)
    {
        if(s[i]=='L')
        {
            charL++;
        }
        if(s[i]=='R')
        {
            charR++;
        }
        if(charR==charL&&charR!=0)
        {
            sum++;
            charR=0;
            charL=0;
        }
    }
    return sum;
}