Skip to content

Commit d21b5b7

Browse files
authored
Create 3803. Count Residue Prefixes.py
1 parent 99664d6 commit d21b5b7

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
3+
'''
4+
1. 아이디어 :
5+
dictionary를 사용해서 distinct를 유지한다.
6+
7+
2. 시간복잡도 :
8+
O(n)
9+
10+
3. 자료구조/알고리즘 :
11+
-
12+
13+
'''
14+
from collections import defaultdict
15+
class Solution:
16+
def residuePrefixes(self, s: str) -> int:
17+
counter = defaultdict(int)
18+
distinct = 0
19+
ans = 0
20+
21+
for i in range(len(s)):
22+
char = s[i]
23+
if counter[char] == 0:
24+
distinct +=1
25+
counter[char] +=1
26+
if (i+1) % 3 == distinct:
27+
ans+=1
28+
return ans

0 commit comments

Comments
 (0)