diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v2/3803. Count Residue Prefixes.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v2/3803. Count Residue Prefixes.py" new file mode 100644 index 00000000..483a4d83 --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v2/3803. Count Residue Prefixes.py" @@ -0,0 +1,23 @@ +''' +1. 아이디어 : +set에 기록하고 길이 재서 구한다. + +2. 시간복잡도 : + O(n) + +3. 자료구조/알고리즘 : +''' +class Solution: + def residuePrefixes(self, s: str) -> int: + n = len(s) + ans = 0 + st = set() + + for i in range(n): + st.add(s[i]) + # print(st, (i+1) % 3) + if len(st) == (i + 1) % 3: + ans += 1 + + + return ans \ No newline at end of file diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v2/837. New 21 Game.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v2/837. New 21 Game.py" new file mode 100644 index 00000000..3c416139 --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v2/837. New 21 Game.py" @@ -0,0 +1,30 @@ +''' +1. 아이디어 : +randint로 그냥 다 구하려고 했으나 시간초과 발생 + +2. 시간복잡도 : + +3. 자료구조/알고리즘 : +''' +from random import randint + +class Solution: + def playGame(self, k, maxPts): + _sum = 0 + while True: + _sum += randint(1,maxPts) + if _sum >= k: + return _sum + + def new21Game(self, n: int, k: int, maxPts: int) -> float: + plays = [] + length = 500000 + + for i in range(length): + plays.append(self.playGame(k,maxPts)) + + # print(plays) + + plays = [i for i in plays if i <= n] + return len(plays) / length + \ No newline at end of file