1915. Number of Wonderful Substrings

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1915

class Solution:
    def wonderfulSubstrings(self, word: str) -> int:
        cnt = Counter({0: 1})
        res = st = 0
        for c in word:
            st ^= 1 << (ord(c) - ord("a"))
            res += cnt[st]
            for i in range(10):
                res += cnt[st ^ (1 << i)]
            cnt[st] += 1
        return res