Posted on 2023-11-16 19:49
Uriel 阅读(28)
评论(0) 编辑 收藏 引用 所属分类:
闲来无事重切Leet Code 、
位运算
给出n个长度为n的二进制数,输出任何一个同样长度为n且与这n个数都不同的二进制数,python的bin()可以方便转二进制
#1980
#Runtime: 11 ms (Beats 91.4%)
#Memory: 13.5 MB (Beats 47.76%)
class Solution(object):
def findDifferentBinaryString(self, nums):
"""
:type nums: List[str]
:rtype: str
"""
n = len(nums)
num_set = set(int(x, 2) for x in nums)
def change_to_n_bit(x, n):
return ("0"*(n - len(x))) + x
for x in xrange(1<<n):
if x not in num_set:
return change_to_n_bit(bin(x)[2:], n)