-
Notifications
You must be signed in to change notification settings - Fork 1
/
weak4_day1.py
43 lines (37 loc) · 879 Bytes
/
weak4_day1.py
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
def solution(N):
value = N
binary = []
while value > 0 :
binary.append(value%2)
value = value // 2
binary = binary[::-1]
i = 0
zero_list = []
while i <len(binary):
if binary[i] == 1:
zero = 0
i = i + 1
while i<len(binary):
if binary[i] == 0:
zero += 1
i = i + 1
else:
zero_list.append(zero)
break
return max(zero_list) if zero_list else 0
N =32
print(solution(N))
'''
모법답안
def solution(N):
binaryNumber = format(N, 'b')
maximum = 0
binaryNumberList = binaryNumber.strip('0').split('1')
for x in binaryNumberList:
if not x:
continue
if len(x) > maximum:
maximum = len(x)
return maximum
print(solution(3243))
'''