@@ -26,6 +26,7 @@ public static void main(String... strings) {
2626printArray_generic_type (nums );
2727CommonUtils .printListList (convertLeetCode2DStringArrayInputIntoJavaArray ("[\" A\" ,\" B\" ],[\" C\" ],[\" B\" ,\" C\" ],[\" D\" ]" ));
2828CommonUtils .print (convertLeetCode1DStringArrayInputIntoJavaArray ("[\" abcsi\" ,\" abyzjgj\" ,\" advz\" ,\" ag\" ,\" agkgdkob\" ,\" agpr\" ,\" ail\" ]" ));
29+ CommonUtils .print2DIntArray (convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray ("[448,931,123,345],[889],[214,962],[576,746,897]" ));
2930 }
3031
3132public static void printArray (boolean []booleans ) {
@@ -292,7 +293,7 @@ public static int[][] convertLeetCodeRegularRectangleArrayInputIntoJavaArray(Str
292293return output ;
293294 }
294295
295- public static int [][]convertLeetCodeIrregularRectangleArrayInputIntoJavaArray (String input ) {
296+ public static int [][]convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray (String input ) {
296297/**
297298 * LeetCode 2-d array input usually comes like this: each row could have different length
298299 * [[448,931,123,345],[889],[214,962],[576,746,897]]
@@ -302,27 +303,32 @@ public static int[][] convertLeetCodeIrregularRectangleArrayInputIntoJavaArray(S
302303 * */
303304String []arrays =input .split ("],\\ [" );
304305int maxLen =0 ;
306+ int []sizes =new int [arrays .length ];
305307for (int i =0 ;i <arrays .length ;i ++) {
306308String []strs =arrays [i ].split ("," );
307309maxLen =Math .max (maxLen ,strs .length );
310+ sizes [i ] =strs .length ;
308311 }
309- int [][]output =new int [arrays .length ][maxLen ];
312+ int [][]output =new int [arrays .length ][];
310313for (int i =0 ;i <arrays .length ;i ++) {
311314if (i ==0 ) {
312315String str =arrays [i ].substring (1 );
313316String []nums =str .split ("," );
314- for (int j =0 ;j <nums .length ;j ++) {
317+ output [i ] =new int [sizes [i ]];
318+ for (int j =0 ;j <sizes [i ];j ++) {
315319output [i ][j ] =Integer .parseInt (nums [j ]);
316320 }
317321 }else if (i ==arrays .length -1 ) {
318322String str =arrays [i ].substring (0 ,arrays [i ].length () -1 );
319323String []nums =str .split ("," );
320- for (int j =0 ;j <nums .length ;j ++) {
324+ output [i ] =new int [sizes [i ]];
325+ for (int j =0 ;j <sizes [i ];j ++) {
321326output [i ][j ] =Integer .parseInt (nums [j ]);
322327 }
323328 }else {
324329String []nums =arrays [i ].split ("," );
325- for (int j =0 ;j <nums .length ;j ++) {
330+ output [i ] =new int [sizes [i ]];
331+ for (int j =0 ;j <sizes [i ];j ++) {
326332output [i ][j ] =Integer .parseInt (nums [j ]);
327333 }
328334 }