File tree 6 files changed +200
-0
lines changed
solution/1900-1999/1980.Find Unique Binary String
6 files changed +200
-0
lines changed Original file line number Diff line number Diff line change @@ -192,4 +192,84 @@ public class Solution {
192
192
193
193
<!-- solution: end -->
194
194
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
+
195
275
<!-- problem: end -->
Original file line number Diff line number Diff line change @@ -191,4 +191,84 @@ public class Solution {
191
191
192
192
<!-- solution: end -->
193
193
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
+
194
274
<!-- problem: end -->
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments