2025-08-15 14:31:44 +0000 UTC

Substrings of Size Three with Distinct Characters

Code

class Solution:
    def countGoodSubstrings(self, s: str) -> int:
        res = 0
        for i in range(len(s) - 2):
            char1, char2, char3 = s[i:i+3]
            if char1 != char2 and char1 != char3 and char2 != char3:
                res += 1
        return res