Posted on

Description

Submission

class Solution {
    int cnt[26];
    int cnt2[26];
public:
    int numSplits(string s) {
        int total = 0;
        for(char c: s) {
            cnt[c-'a']++;
            if(cnt[c-'a'] == 1) total++; // left + right
        }

        int left = 0, ret = 0;
        for(char c: s) {
            int tmp = 0;
            cnt2[c-'a']++;
            if(cnt2[c-'a'] == 1) left++; // left includes
            for(int i = 0; i < 26; ++i) {
                if(cnt[i] != 0 && cnt2[i] == cnt[i]) tmp++; // only by left
            }
            if(left == total - tmp) ret++;
        }
        return ret;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *