Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int balancedString(string s) {
- unordered_map<char, int> count;
- int left, right, n=s.length(), k=n/4;
- for(int i=0; i<n; i++)
- count[s[i]]++;
- int ans = n;
- for(left=0, right=0; right<n; right++){
- count[s[right]]--;
- while(left<n && count['Q']<=k && count['W']<=k && count['E']<=k && count['R']<=k){
- ans = min(ans, right-left+1);
- count[s[left++]] += 1;
- }
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement