Number of Good Ways to Split a String

给一个字符串s, 求有多少种分割方法, 让分割的两个字符串的不同字符数量相同.

class Solution {
    public int numSplits(String s) {
        int res = 0;
        Map<Character, Integer> map = new HashMap<>();
        for(char c : s.toCharArray())
            map.put(c, map.getOrDefault(c, 0) + 1);
        Map<Character, Integer> left = new HashMap<>();
        for(char c : s.toCharArray()){
            left.put(c, left.getOrDefault(c, 0) + 1);
            map.put(c, map.get(c) - 1);
            if(map.get(c) == 0)
                map.remove(c);
            if(map.size() == left.size())
                res++;
        }
        return res;
    }
}