Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

binary gap python

def solution(N):
    my_binary = format(N, "b")
    my_list = list(my_binary)
    keeper = []
    count = 0
    print(my_binary)
    for x in range(len(my_list)):
        if my_list[x] == '1':
            if x == len(my_list) - 1 or my_list[x + 1] == '1':
                pass
            else:
                keeper.append(changer(x, my_list))

        for q in keeper:
            if q == 0:
                pass
            elif count < (q[1] - q[0]):
                count = q[1] - q[0]
    return count


def changer(x, my_list):
    for y in range(x, len(my_list)):
        if my_list[y] == '0' and y != len(my_list) - 1 and my_list[y + 1] == '1':
            return [x, y]
    return 0

print(solution(11))
Comment

PREVIOUS NEXT
Code Example
Python :: python crop string 
Python :: python parcourir ligne 
Python :: write pyspark dataframe to csv 
Python :: python extract string 
Python :: python file modes 
Python :: flask session timeout 
Python :: python turtle fill 
Python :: nonlocal keyword python 
Python :: django message 
Python :: pyautogui locatecenteronscreen mac fix 
Python :: pandas series plot horizontal bar 
Python :: What is the use of f in python? 
Python :: how to make every letter capital in python 
Python :: static files not loading 404 error django 
Python :: inherit init method 
Python :: days in month function python 
Python :: blender show python version 
Python :: Pandas conditional collumn 
Python :: python list directories only 
Python :: geopandas geometry length 
Python :: django error handling < form 
Python :: BURGERS2 codechef solution 
Python :: read part of file pandas 
Python :: iterate through a list 
Python :: how to get what type of file a file is in python 
Python :: Python Making a New Directory 
Python :: access myultiple dict values with list pythojn 
Python :: react-native-dropdown-picker 
Python :: python password generation 
Python :: matplotlib larger chart 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =