blob: 6866870ba41bba8528750a33c5bc259e65b8a73c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# 1980. Find Unique Binary String
"""
given an array of strings 'nums' containing 'n' unique binary strings each of
length 'n', return a binary string of length 'n' that does not appear in
'nums'. if there are multiple answers, you may return any of them.
"""
class Solution(object):
def findDifferentBinaryString(self, nums):
"""
:type nums: List[str]
:rtype: str
"""
s = set([int(i, 2) for i in nums])
max_len = len(nums[0])
for i in range(pow(2, max_len)):
if i not in s:
r = bin(i)[2:]
return "0" * (max_len - len(r)) + r
return "-1"
if __name__ == "__main__":
obj = Solution()
print(obj.findDifferentBinaryString(["01", "10"])) # expect: 11
print(obj.findDifferentBinaryString(["00", "01"])) # expect: 11
print(obj.findDifferentBinaryString(["111", "011", "001"])) # expect: 101
|