Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a6c9fbe

Browse files
authored
feat: add solutions to lc problem: No.1980 (#4085)
1 parent 463bcc0 commit a6c9fbe

File tree

6 files changed

+200
-0
lines changed

6 files changed

+200
-0
lines changed

‎solution/1900-1999/1980.Find Unique Binary String/README.md‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,84 @@ public class Solution {
192192

193193
<!-- solution:end -->
194194

195+
<!-- solution:start -->
196+
197+
### 方法二
198+
199+
<!-- tabs:start -->
200+
201+
#### TypeScript
202+
203+
```ts
204+
function findDifferentBinaryString(nums: string[]): string {
205+
const set = new Set(nums.map(x => Number.parseInt(x, 2)));
206+
let res = 0;
207+
208+
while (set.has(res)) {
209+
res++;
210+
}
211+
212+
return res.toString(2).padStart(nums[0].length, '0');
213+
}
214+
```
215+
216+
#### JavaScript
217+
218+
```js
219+
function findDifferentBinaryString(nums) {
220+
const set = new Set(nums.map(x => Number.parseInt(x, 2)));
221+
let res = 0;
222+
223+
while (set.has(res)) {
224+
res++;
225+
}
226+
227+
return res.toString(2).padStart(nums[0].length, '0');
228+
}
229+
```
230+
231+
<!-- solution:end -->
232+
233+
<!-- tabs:end -->
234+
235+
<!-- solution:start -->
236+
237+
### 方法三
238+
239+
<!-- tabs:start -->
240+
241+
#### TypeScript
242+
243+
```ts
244+
function findDifferentBinaryString(nums: string[]): string {
245+
const res: string[] = [];
246+
247+
for (let i = 0; i < nums.length; i++) {
248+
const x = nums[i][i];
249+
res.push(x === '0' ? '1' : '0');
250+
}
251+
252+
return res.join('');
253+
}
254+
```
255+
256+
#### JavaScript
257+
258+
```js
259+
function findDifferentBinaryString(nums) {
260+
const res = [];
261+
262+
for (let i = 0; i < nums.length; i++) {
263+
const x = nums[i][i];
264+
res.push(x === '0' ? '1' : '0');
265+
}
266+
267+
return res.join('');
268+
}
269+
```
270+
271+
<!-- solution:end -->
272+
273+
<!-- tabs:end -->
274+
195275
<!-- problem:end -->

‎solution/1900-1999/1980.Find Unique Binary String/README_EN.md‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,84 @@ public class Solution {
191191

192192
<!-- solution:end -->
193193

194+
<!-- solution:start -->
195+
196+
### Solution 2
197+
198+
<!-- tabs:start -->
199+
200+
#### TypeScript
201+
202+
```ts
203+
function findDifferentBinaryString(nums: string[]): string {
204+
const set = new Set(nums.map(x => Number.parseInt(x, 2)));
205+
let res = 0;
206+
207+
while (set.has(res)) {
208+
res++;
209+
}
210+
211+
return res.toString(2).padStart(nums[0].length, '0');
212+
}
213+
```
214+
215+
#### JavaScript
216+
217+
```js
218+
function findDifferentBinaryString(nums) {
219+
const set = new Set(nums.map(x => Number.parseInt(x, 2)));
220+
let res = 0;
221+
222+
while (set.has(res)) {
223+
res++;
224+
}
225+
226+
return res.toString(2).padStart(nums[0].length, '0');
227+
}
228+
```
229+
230+
<!-- solution:end -->
231+
232+
<!-- tabs:end -->
233+
234+
<!-- solution:start -->
235+
236+
### Solution 3
237+
238+
<!-- tabs:start -->
239+
240+
#### TypeScript
241+
242+
```ts
243+
function findDifferentBinaryString(nums: string[]): string {
244+
const res: string[] = [];
245+
246+
for (let i = 0; i < nums.length; i++) {
247+
const x = nums[i][i];
248+
res.push(x === '0' ? '1' : '0');
249+
}
250+
251+
return res.join('');
252+
}
253+
```
254+
255+
#### JavaScript
256+
257+
```js
258+
function findDifferentBinaryString(nums) {
259+
const res = [];
260+
261+
for (let i = 0; i < nums.length; i++) {
262+
const x = nums[i][i];
263+
res.push(x === '0' ? '1' : '0');
264+
}
265+
266+
return res.join('');
267+
}
268+
```
269+
270+
<!-- solution:end -->
271+
272+
<!-- tabs:end -->
273+
194274
<!-- problem:end -->
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function findDifferentBinaryString(nums) {
2+
const set = new Set(nums.map(x => Number.parseInt(x, 2)));
3+
let res = 0;
4+
5+
while (set.has(res)) {
6+
res++;
7+
}
8+
9+
return res.toString(2).padStart(nums[0].length, '0');
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function findDifferentBinaryString(nums: string[]): string {
2+
const set = new Set(nums.map(x => Number.parseInt(x, 2)));
3+
let res = 0;
4+
5+
while (set.has(res)) {
6+
res++;
7+
}
8+
9+
return res.toString(2).padStart(nums[0].length, '0');
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function findDifferentBinaryString(nums) {
2+
const res = [];
3+
4+
for (let i = 0; i < nums.length; i++) {
5+
const x = nums[i][i];
6+
res.push(x === '0' ? '1' : '0');
7+
}
8+
9+
return res.join('');
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function findDifferentBinaryString(nums: string[]): string {
2+
const res: string[] = [];
3+
4+
for (let i = 0; i < nums.length; i++) {
5+
const x = nums[i][i];
6+
res.push(x === '0' ? '1' : '0');
7+
}
8+
9+
return res.join('');
10+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /