diff --git "a/leetcode3/\353\202\250\355\232\250\354\240\225/3803. Count Residue Prefixes.py" "b/leetcode3/\353\202\250\355\232\250\354\240\225/3803. Count Residue Prefixes.py" new file mode 100644 index 00000000..6f6b6f9b --- /dev/null +++ "b/leetcode3/\353\202\250\355\232\250\354\240\225/3803. Count Residue Prefixes.py" @@ -0,0 +1,16 @@ +class Solution: + def residuePrefixes(self, s: str) -> int: + ans = 0 + check = set() + + for i, char in enumerate(s): + check.add(char) + + # 종류가 3가지 이상이 되면 더 계산할 필요 없음 + if len(check) >= 3: + break + + # 문제에서 원하는 조건 만족할 때마다 정답 개수 += 1 + if len(check) == (i + 1) % 3: + ans += 1 + return ans \ No newline at end of file diff --git "a/leetcode3/\353\202\250\355\232\250\354\240\225/837. New 21 Game.py" "b/leetcode3/\353\202\250\355\232\250\354\240\225/837. New 21 Game.py" new file mode 100644 index 00000000..2e57a97e --- /dev/null +++ "b/leetcode3/\353\202\250\355\232\250\354\240\225/837. New 21 Game.py" @@ -0,0 +1,20 @@ +# 풀이 실패 +class Solution: + def new21Game(self, n: int, k: int, maxPts: int) -> float: + if k == 0 or n >= k + maxPts: + return 1.0 + + dp = [0.0] * (n + 1) + dp[0] = 1.0 + window_sum = 1.0 + + for i in range(1, n+1): + dp[i] = window_sum / maxPts + + if i < k: + window_sum += dp[i] + + if i >= maxPts and (i - maxPts) < k: + window_sum -= dp[i - maxPts] + + return sum(dp[k:]) \ No newline at end of file