This is my CPP solution.
class Solution {
public:
int balancedStringSplit(string s) {
int cnt = 0;
string stack;
for(int i=0;i<s.size();i++){
stack.push_back(s[i]);
int n = stack.size();
if(n>1 && stack[n-1]!=stack[n-2]){
stack.pop_back();
stack.pop_back();
}
if(stack.size() == 0){
cnt++;
}
}
return cnt;
}
};