-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path481.py
More file actions
43 lines (42 loc) · 1.41 KB
/
481.py
File metadata and controls
43 lines (42 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
__________________________________________________________________________________________________
sample 60 ms submission
s = [1,2,2]
index = 2
while len(s) < 100000:
# according to the last element, we decide the value of 'val'
val = 3 - s[-1]
s.extend([val]*s[index])
index += 1
class Solution(object):
def magicalString(self, n):
"""
:type n: int
:rtype: int
"""
return s[:n].count(1)
__________________________________________________________________________________________________
sample 14004 kb submission
class Solution:
def magicalString(self, n: int) -> int:
s_list = list(map(int,"1221121221221121122"))
S = "1221121221221121122"
S_len = len(S)
if n<=S_len:
return S[:n].count("1")
else:
count = 19
i = 12
while count<n:
if not i%2:
S+=s_list[i]*'1'
# s_list.append(s_list[i])
# s_list = list(map(int,S))
else:
S+=s_list[i]*'2'
# s_list.append(s_list[i])
# s_list = list(map(int,S))
s_list.append(int(S[len(s_list)]))
count += s_list[i]
i+=1
return S[:n].count("1")
__________________________________________________________________________________________________