Skip to content

Commit 3f1eeea

Browse files
authored
Create substrings-of-size-three-with-distinct-characters.py
1 parent 1423d09 commit 3f1eeea

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
import collections
5+
6+
7+
class Solution(object):
8+
def countGoodSubstrings(self, s):
9+
"""
10+
:type s: str
11+
:rtype: int
12+
"""
13+
K = 3
14+
15+
result = 0
16+
count = collections.Counter()
17+
for i in xrange(len(s)):
18+
if i >= K:
19+
count[s[i-K]] -= 1
20+
if not count[s[i-K]]:
21+
del count[s[i-K]]
22+
count[s[i]] += 1
23+
if len(count) == K:
24+
result += 1
25+
return result

0 commit comments

Comments
 (0)