Skip to content

Instantly share code, notes, and snippets.

@parcar
Created August 20, 2019 20:18
Show Gist options
  • Select an option

  • Save parcar/0ebba69eea6ec435ee047b19ab4c8884 to your computer and use it in GitHub Desktop.

Select an option

Save parcar/0ebba69eea6ec435ee047b19ab4c8884 to your computer and use it in GitHub Desktop.
class Solution(object):
def findComplement(self, num):
"""
:type num: int
:rtype: int
"""
binary = [int(i) ^ 1 for i in bin(num)[2:]]
return int("".join(map(str,binary)),2)
'''
Runtime: 12 ms, faster than 89.42% of Python online submissions for Number Complement.
Memory Usage: 11.9 MB, less than 14.29% of Python online submissions for Number Complement.
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment