Skip to content

Commit e3038e2

Browse files
committed
837,3803
1 parent 9763da6 commit e3038e2

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'''
2+
1. 아이디어 :
3+
set에 기록하고 길이 재서 구한다.
4+
5+
2. 시간복잡도 :
6+
O(n)
7+
8+
3. 자료구조/알고리즘 :
9+
'''
10+
class Solution:
11+
def residuePrefixes(self, s: str) -> int:
12+
n = len(s)
13+
ans = 0
14+
st = set()
15+
16+
for i in range(n):
17+
st.add(s[i])
18+
# print(st, (i+1) % 3)
19+
if len(st) == (i + 1) % 3:
20+
ans += 1
21+
22+
23+
return ans
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'''
2+
1. 아이디어 :
3+
randint로 그냥 다 구하려고 했으나 시간초과 발생
4+
5+
2. 시간복잡도 :
6+
7+
3. 자료구조/알고리즘 :
8+
'''
9+
from random import randint
10+
11+
class Solution:
12+
def playGame(self, k, maxPts):
13+
_sum = 0
14+
while True:
15+
_sum += randint(1,maxPts)
16+
if _sum >= k:
17+
return _sum
18+
19+
def new21Game(self, n: int, k: int, maxPts: int) -> float:
20+
plays = []
21+
length = 500000
22+
23+
for i in range(length):
24+
plays.append(self.playGame(k,maxPts))
25+
26+
# print(plays)
27+
28+
plays = [i for i in plays if i <= n]
29+
return len(plays) / length
30+

0 commit comments

Comments
 (0)