https://app.codility.com/programmers/lessons/1-iterations/
1. Iterations lesson - Learn to Code - Codility
Find longest sequence of zeros in binary representation of an integer.
app.codility.com
def solution(N):
binary = bin(N).lstrip('0b')
cnt = 0
maxc = 0
for i in binary:
if i=='1':
if maxc < cnt :
maxc = cnt
cnt = 0
else:
cnt += 1
return maxc
반응형
최근댓글