반응형
A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.
Write a function:
def solution(N):
that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap.
My answer:
def solution(N):
a= max(bin(N).split('b')[1].strip('0').strip('1').split('1'))
return len(a)
반응형
'Language > Python' 카테고리의 다른 글
[Python ]Practice algorithm - multiplication of complex number (0) | 2020.07.28 |
---|---|
Session-자료구조 Stack & Queue (0) | 2020.05.26 |
Session-쉘과 sql, 파이썬 코드로 접근하기(shell , sql, python, django) (0) | 2020.05.19 |
Session-TIP-Django 장고 , 개발자에게 좋은 팁 (0) | 2020.05.17 |
TIL - 셀레니움 (Selenium) 기초!! (0) | 2020.05.16 |