/**
* Problem: LeetCode 1980 - Find Unique Binary String
* Difficulty: Medium
* Language: Java
* Author: CodeByTushu
*/
class Solution {
public String findDifferentBinaryString(String[] nums) {
StringBuilder sb = new StringBuilder();
int n = nums.length;
// Cantor's Diagonalization:
// Construct string such that char at index i differs from nums[i].charAt(i)
for (int i = 0; i < n; i++) {
sb.append(nums[i].charAt(i) == '0' ? '1' : '0');
}
return sb.toString();
}
}
"""
Problem: LeetCode 1980 - Find Unique Binary String
Difficulty: Medium
Language: Python
Author: CodeByTushu
"""
from typing import List
class Solution:
def findDifferentBinaryString(self, nums: List[str]) -> str:
# Cantor's Diagonal Argument:
# Construct a string where the i-th character is inverted from nums[i][i]
return "".join('1' if nums[i][i] == '0' else '0' for i in range(len(nums)))
/**
* Problem: LeetCode 1980 - Find Unique Binary String
* Difficulty: Medium
* Language: C++
* Author: CodeByTushu
*/
#include <vector>
#include <string>
using namespace std;
class Solution {
public:
string findDifferentBinaryString(vector<string>& nums) {
string res = "";
int n = nums.size();
// Cantor's Diagonalization:
// Flip the diagonal bit nums[i][i] so res differs from every nums[i]
for (int i = 0; i < n; i++) {
res += (nums[i][i] == '0' ? '1' : '0');
}
return res;
}
};
/**
* Problem: LeetCode 1980 - Find Unique Binary String
* Difficulty: Medium
* Language: JavaScript
* Author: CodeByTushu
*/
/**
* @param {string[]} nums
* @return {string}
*/
var findDifferentBinaryString = function(nums) {
const n = nums.length;
let res = "";
// Cantor's Diagonalization:
// Invert the i-th character of the i-th string
for (let i = 0; i < n; i++) {
res += nums[i][i] === '0' ? '1' : '0';
}
return res;
};