-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1980. Find Unique Binary String #1339
Comments
We need to find a binary string of length ApproachThe key idea is to construct a binary string where each bit is chosen such that it differs from the corresponding bit in each of the strings in Let's implement this solution in PHP: 1980. Find Unique Binary String <?php
/**
* @param String[] $nums
* @return String
*/
function findDifferentBinaryString($nums) {
$n = count($nums);
$result = '';
for ($i = 0; $i < $n; $i++) {
$s = $nums[$i];
$c = $s[$i];
$result .= ($c === '0' ? '1' : '0');
}
return $result;
}
// Test cases
$nums1 = ["01", "10"];
echo findDifferentBinaryString($nums1) . "\n";
$nums2 = ["00", "01"];
echo findDifferentBinaryString($nums2) . "\n";
$nums3 = ["111", "011", "001"];
echo findDifferentBinaryString($nums3) . "\n";
?> Explanation:
This approach efficiently constructs the required string in O(n) time complexity, where |
…ssions 1549745625 Co-authored-by: kovatz <[email protected]> Co-authored-by: topugit <[email protected]> Co-authored-by: basharul-siddike <[email protected]> Co-authored-by: hafijul233 <[email protected]>
Discussed in #1338
Originally posted by mah-shamim February 20, 2025
Topics:
Array
,Hash Table
,String
,Backtracking
Given an array of strings
nums
containingn
unique binary strings each of lengthn
, return a binary string of lengthn
that does not appear innums
. If there are multiple answers, you may return any of them.Example 1:
Example 2:
Example 3:
Constraints:
n == nums.length
1 <= n <= 16
nums[i].length == n
nums[i]
is either'0'
or'1'
.nums
are unique.Hint:
The text was updated successfully, but these errors were encountered: