- categories: Code, Interview Question, leetcode, Medium
- source: https://leetcode.com/problems/find-unique-binary-string
- topics: String Manipulation
Description
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.
Idea
- Use the force of Python
- Use diagonal search
Code
Force
class Solution:
def findDifferentBinaryString(self, nums: List[str]) -> str:
return next(iter(set(map("".join, product(*["01"] * len(nums)))) - set(nums)))
Diagonal
class Solution:
def findDifferentBinaryString(self, nums):
result = []
for i in range(len(nums)):
if nums[i][i] == '0':
result.append('1')
else:
result.append('0')
return ''.join(result)