Python using Binary Method


  • 0
    J

    So I didn't know what binary representation and binary operators (such as >> and <<) were. I came across the bin(ary) method for python and it looked pretty cool. pretty simple and works fine.

    def findC(nums):
        c = bin(num)[2::]
        ans = ''
        for i in c:
            if i=='0': ans += '1'
            elif i=='1': ans += '0'
        return int(ans,2)
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.