File tree 1 file changed +29
-0
lines changed
src/main/java/com/fishercoder/common/utils
1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -253,4 +253,33 @@ public static void print2DCharArray(char[][] arrayArrays) {
253
253
}
254
254
System .out .println ();
255
255
}
256
+
257
+ public static int [][] convertLeetCodeArrayInputIntoJavaArray (String input ) {
258
+ String [] arrays = input .split ("],\\ [" );
259
+ // CommonUtils.printArray_generic_type(arrays);
260
+ int size = arrays [1 ].split ("," ).length ;
261
+ int [][] output = new int [arrays .length ][size ];
262
+ for (int i = 0 ; i < arrays .length ; i ++) {
263
+ if (i == 0 ) {
264
+ String str = arrays [i ].substring (1 );
265
+ String [] nums = str .split ("," );
266
+ for (int j = 0 ; j < nums .length ; j ++) {
267
+ output [i ][j ] = Integer .parseInt (nums [j ]);
268
+ }
269
+ } else if (i == arrays .length - 1 ) {
270
+ String str = arrays [i ].substring (0 , arrays [i ].length () - 1 );
271
+ String [] nums = str .split ("," );
272
+ for (int j = 0 ; j < nums .length ; j ++) {
273
+ output [i ][j ] = Integer .parseInt (nums [j ]);
274
+ }
275
+ } else {
276
+ String [] nums = arrays [i ].split ("," );
277
+ for (int j = 0 ; j < nums .length ; j ++) {
278
+ output [i ][j ] = Integer .parseInt (nums [j ]);
279
+ }
280
+ }
281
+ }
282
+ // CommonUtils.print2DIntArray(output);
283
+ return output ;
284
+ }
256
285
}
You can’t perform that action at this time.
0 commit comments