Leetcode-5222 Split a String in Balanced Strings(分割平衡字符串)
1 using namespace std; 2 typedef pair<int,int> P; 3 typedef long long ll; 4 #define _for(i,a,b) for(register int i = (a);i < b;i ++) 5 #define _rep(i,a,b) for(register int i = (a);i > b;i --) 6 #define INF 0x3f3f3f3f 7 #define MOD 100000000 8 #define maxn 1003 9 #define pb push_back 10 #define debug() printf("Miku Check OK!\n") 11 12 13 class Solution 14 { 15 public: 16 int balancedStringSplit(string s) 17 { 18 int rnt = 0; 19 int k1 = 0,k2 = 0; 20 _for(i,0,s.size()) 21 { 22 if(s[i]=='L') 23 k1 ++; 24 else 25 k2 ++; 26 if(k1==k2) 27 rnt ++; 28 } 29 return rnt; 30 } 31 };