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
반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기