Skip to content

Commit a1748fb

Browse files
committed
Sync LeetCode submission Runtime - 0 ms (100.00%), Memory - 17.7 MB (69.31%)
1 parent 70be960 commit a1748fb

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <strong>any</strong> of them</em>.</p>
2+
3+
<p>&nbsp;</p>
4+
<p><strong class="example">Example 1:</strong></p>
5+
6+
<pre>
7+
<strong>Input:</strong> nums = [&quot;01&quot;,&quot;10&quot;]
8+
<strong>Output:</strong> &quot;11&quot;
9+
<strong>Explanation:</strong> &quot;11&quot; does not appear in nums. &quot;00&quot; would also be correct.
10+
</pre>
11+
12+
<p><strong class="example">Example 2:</strong></p>
13+
14+
<pre>
15+
<strong>Input:</strong> nums = [&quot;00&quot;,&quot;01&quot;]
16+
<strong>Output:</strong> &quot;11&quot;
17+
<strong>Explanation:</strong> &quot;11&quot; does not appear in nums. &quot;10&quot; would also be correct.
18+
</pre>
19+
20+
<p><strong class="example">Example 3:</strong></p>
21+
22+
<pre>
23+
<strong>Input:</strong> nums = [&quot;111&quot;,&quot;011&quot;,&quot;001&quot;]
24+
<strong>Output:</strong> &quot;101&quot;
25+
<strong>Explanation:</strong> &quot;101&quot; does not appear in nums. &quot;000&quot;, &quot;010&quot;, &quot;100&quot;, and &quot;110&quot; would also be correct.
26+
</pre>
27+
28+
<p>&nbsp;</p>
29+
<p><strong>Constraints:</strong></p>
30+
31+
<ul>
32+
<li><code>n == nums.length</code></li>
33+
<li><code>1 &lt;= n &lt;= 16</code></li>
34+
<li><code>nums[i].length == n</code></li>
35+
<li><code>nums[i] </code>is either <code>&#39;0&#39;</code> or <code>&#39;1&#39;</code>.</li>
36+
<li>All the strings of <code>nums</code> are <strong>unique</strong>.</li>
37+
</ul>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Approach 4: Cantor's Diagonal Argument
2+
3+
# Time: O(n)
4+
# Space: O(1)
5+
6+
class Solution:
7+
def findDifferentBinaryString(self, nums: List[str]) -> str:
8+
ans = []
9+
10+
for i in range(len(nums)):
11+
curr = nums[i][i]
12+
ans.append('1' if curr == '0' else '0')
13+
14+
return ''.join(ans)
15+

0 commit comments

Comments
 (0)