1525. Number of Good Ways to Split a String (Medium) - TengnanYao/daily_leetcode GitHub Wiki

class Solution:
    def numSplits(self, s: str) -> int:
        h = collections.Counter(s)
        h1 = {}
        result = 0
        for c in s:
            h1[c] = h.get(c, 0) + 1
            h[c] -= 1
            if h[c] == 0:
                del h[c]
            if len(h) == len(h1):
                result += 1
            if len(h1) > len(h):
                return result