@@ -264,6 +264,40 @@ public static void print2DCharArray(char[][] arrayArrays) {
264
264
System .out .println ();
265
265
}
266
266
267
+ public static char [][] convertLeetCodeRegular2DCharArrayInputIntoJavaArray (String input ) {
268
+ /**LeetCode 2-d char array usually comes in like this:
269
+ * [["#"," ","#"],[" "," ","#"],["#","c"," "]] which is wrapped in double quotes instead of single quotes which makes it not usable in Java code.
270
+ * This method helps with the conversion.*/
271
+ input = input .substring (1 , input .length () - 1 );
272
+ String [] arrays = input .split ("],\\ [" );
273
+ // CommonUtils.printArray_generic_type(arrays);
274
+ int m = arrays .length ;
275
+ int n = arrays [1 ].split ("," ).length ;
276
+ char [][] ans = new char [m ][n ];
277
+ for (int i = 0 ; i < m ; i ++) {
278
+ if (i == 0 ) {
279
+ String str = arrays [i ].substring (1 );
280
+ String [] strs = str .split ("," );
281
+ for (int j = 0 ; j < strs .length ; j ++) {
282
+ ans [i ][j ] = strs [j ].charAt (1 );
283
+ }
284
+ } else if (i == m - 1 ) {
285
+ String str = arrays [i ].substring (0 , arrays [i ].length () - 1 );
286
+ String [] strs = str .split ("," );
287
+ for (int j = 0 ; j < strs .length ; j ++) {
288
+ ans [i ][j ] = strs [j ].charAt (1 );
289
+ }
290
+ } else {
291
+ String [] strs = arrays [i ].split ("," );
292
+ for (int j = 0 ; j < strs .length ; j ++) {
293
+ ans [i ][j ] = strs [j ].charAt (1 );
294
+ }
295
+ }
296
+ }
297
+ CommonUtils .print2DCharArray (ans );
298
+ return ans ;
299
+ }
300
+
267
301
public static int [][] convertLeetCodeRegularRectangleArrayInputIntoJavaArray (String input ) {
268
302
/**
269
303
* LeetCode 2-d array input usually comes like this: it's a REGULAR rectangle
0 commit comments