@@ -317,26 +317,35 @@ public static int[][] convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(S
317
317
sizes [i ] = strs .length ;
318
318
}
319
319
int [][] output = new int [arrays .length ][];
320
- for (int i = 0 ; i < arrays .length ; i ++) {
321
- if (i == 0 ) {
322
- String str = arrays [i ].substring (1 );
323
- String [] nums = str .split ("," );
324
- output [i ] = new int [sizes [i ]];
325
- for (int j = 0 ; j < sizes [i ]; j ++) {
326
- output [i ][j ] = Integer .parseInt (nums [j ]);
327
- }
328
- } else if (i == arrays .length - 1 ) {
329
- String str = arrays [i ].substring (0 , arrays [i ].length () - 1 );
330
- String [] nums = str .split ("," );
331
- output [i ] = new int [sizes [i ]];
332
- for (int j = 0 ; j < sizes [i ]; j ++) {
333
- output [i ][j ] = Integer .parseInt (nums [j ]);
334
- }
335
- } else {
336
- String [] nums = arrays [i ].split ("," );
337
- output [i ] = new int [sizes [i ]];
338
- for (int j = 0 ; j < sizes [i ]; j ++) {
339
- output [i ][j ] = Integer .parseInt (nums [j ]);
320
+ if (arrays .length == 1 ) {
321
+ String str = arrays [0 ].substring (1 , arrays [0 ].length () - 1 );
322
+ String [] nums = str .split ("," );
323
+ output [0 ] = new int [sizes [0 ]];
324
+ for (int j = 0 ; j < sizes [0 ]; j ++) {
325
+ output [0 ][j ] = Integer .parseInt (nums [j ]);
326
+ }
327
+ } else {
328
+ for (int i = 0 ; i < arrays .length ; i ++) {
329
+ if (i == 0 ) {
330
+ String str = arrays [i ].substring (1 );
331
+ String [] nums = str .split ("," );
332
+ output [i ] = new int [sizes [i ]];
333
+ for (int j = 0 ; j < sizes [i ]; j ++) {
334
+ output [i ][j ] = Integer .parseInt (nums [j ]);
335
+ }
336
+ } else if (i == arrays .length - 1 ) {
337
+ String str = arrays [i ].substring (0 , arrays [i ].length () - 1 );
338
+ String [] nums = str .split ("," );
339
+ output [i ] = new int [sizes [i ]];
340
+ for (int j = 0 ; j < sizes [i ]; j ++) {
341
+ output [i ][j ] = Integer .parseInt (nums [j ]);
342
+ }
343
+ } else {
344
+ String [] nums = arrays [i ].split ("," );
345
+ output [i ] = new int [sizes [i ]];
346
+ for (int j = 0 ; j < sizes [i ]; j ++) {
347
+ output [i ][j ] = Integer .parseInt (nums [j ]);
348
+ }
340
349
}
341
350
}
342
351
}
0 commit comments