From d21b5b7df52a2e6153ae07597e0a9f9aaaf99bcb Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Tue, 11 Aug 2026 22:39:49 +0900 Subject: [PATCH] Create 3803. Count Residue Prefixes.py --- .../3803. Count Residue Prefixes.py" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/3803. Count Residue Prefixes.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/3803. Count Residue Prefixes.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/3803. Count Residue Prefixes.py" new file mode 100644 index 00000000..d8f3d91c --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/3803. Count Residue Prefixes.py" @@ -0,0 +1,28 @@ +# + +''' +1. 아이디어 : +dictionary를 사용해서 distinct를 유지한다. + +2. 시간복잡도 : + O(n) + +3. 자료구조/알고리즘 : +- + +''' +from collections import defaultdict +class Solution: + def residuePrefixes(self, s: str) -> int: + counter = defaultdict(int) + distinct = 0 + ans = 0 + + for i in range(len(s)): + char = s[i] + if counter[char] == 0: + distinct +=1 + counter[char] +=1 + if (i+1) % 3 == distinct: + ans+=1 + return ans