diff options
author | Jack Sangdahl <[email protected]> | 2025-02-19 17:34:23 -0700 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-02-19 17:34:23 -0700 |
commit | f4a2492a0b821a6587e856b3a792b110d6bccf96 (patch) | |
tree | 252c996e65e112a6e117d8343ed17559d9760926 /find_unique_binary_str.py | |
parent | cf719c0935f5c19e902586ddedcf2ae1bc887b4a (diff) | |
download | leetcode-f4a2492a0b821a6587e856b3a792b110d6bccf96.tar.gz leetcode-f4a2492a0b821a6587e856b3a792b110d6bccf96.zip |
1980. find unique binary string
Diffstat (limited to 'find_unique_binary_str.py')
-rw-r--r-- | find_unique_binary_str.py | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/find_unique_binary_str.py b/find_unique_binary_str.py index 6866870..681369b 100644 --- a/find_unique_binary_str.py +++ b/find_unique_binary_str.py @@ -13,17 +13,11 @@ class Solution(object): :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" + return "".join(["1" if num[i] == "0" else "0" for i, num in enumerate(nums)]) 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 + print(obj.findDifferentBinaryString(nums=["01", "10"])) + print(obj.findDifferentBinaryString(nums=["00", "01"])) + print(obj.findDifferentBinaryString(nums=["111", "011", "001"])) |