Number of Substrings Containing All Three Characters LeetCode solution in Python

1
# Runtime: 466 ms (Top 30.17%) | Memory: 14.4 MB (Top 31.83%)
2
class Solution:
3
def numberOfSubstrings(self, s: str) -> int:
4
start = 0
5
end = 0
6
counter = 0
7
store = {"a": 0, "b": 0, "c": 0}
8

9
for end in range(len(s)):
10
store[s[end]] += 1
11

12
while store["a"] > 0 and store["b"] > 0 and store["c"] > 0:
13
counter += len(s) - end
14
store[s[start]] -= 1
15
start += 1
16

17
return counter

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0