1 parent 99664d6 commit d21b5b7Copy full SHA for d21b5b7
1 file changed
leetcode3/최원준/3803. Count Residue Prefixes.py
@@ -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