[codility] Solution to Binary-Gap by codility (python)
728x90
반응형
Question: https://codility.com/demo/take-sample-test/binary_gap
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
cur,max_gap=0,0
for i,e in enumerate(str(bin(N)[2:])):
if e=='1':
max_gap=max(max_gap,cur)
cur=0
else:
cur+=1
return max_gap
728x90
반응형
'codility' 카테고리의 다른 글
[codility] max counters (python) (0) | 2020.10.14 |
---|---|
[codility] TapeEquilibrium (python) (0) | 2020.10.14 |
[codility] perm missing elem (python) (0) | 2020.10.14 |
[codility] frog river one (python) (0) | 2020.10.14 |
[Codility] lession2 - OddOccurrencesInArray (python, bitwise) (0) | 2020.10.14 |
TAGS.