LeetCode #1876: Substrings of Size Three with Distinct Characters
β’ 53 words β’ 1 min
LeetCode #1876: Substrings of Size Three with Distinct Characters:
python
class Solution:
def countGoodSubstrings(self, s: str) -> int:
def good(s):
return len(s) == 3 and s[0] != s[1] and s[1] != s[2] and s[2] != s[0]
ans = 0
for i in range(0, len(s) - 2):
ans += good(s[i:i + 3])
return ans