<reponame>Linchin/python_leetcode_git
"""
1525
medium
number of good ways to split a string
"""


class Solution:
    def numSplits(self, s: str) -> int:

        from collections import Counter

        left = Counter()
        right = Counter(s)
        total = 0

        for c in s:
            left[c] += 1
            right[c] -= 1
            if right[c] == 0:
                del right[c]
            if len(left) == len(right):
                total += 1

        return total
s = "aacaba"
sol = Solution()
print(sol.numSplits(s))



"""
1525
medium
number of good ways to split a string
"""


class Solution:
    def numSplits(self, s: str) -> int:

        from collections import Counter

        left = Counter()
        right = Counter(s)
        total = 0

        for c in s:
            left[c] += 1
            right[c] -= 1
            if right[c] == 0:
                del right[c]
            if len(left) == len(right):
                total += 1

        return total
s = "aacaba"
sol = Solution()
print(sol.numSplits(s))
1525 medium number of good ways to split a string