2
2
3
3
import com .fishercoder .common .classes .Interval ;
4
4
import com .fishercoder .common .classes .ListNode ;
5
-
6
5
import java .util .ArrayList ;
7
6
import java .util .Deque ;
8
7
import java .util .List ;
@@ -13,7 +12,7 @@ public class CommonUtils {
13
12
private static final int DEFAULT_TREE_SIZE = 10 ;
14
13
private static final int DEFAULT_UPPER_BOUND = 100 ;
15
14
16
- //How to make a method generic: declare <T> in its method signature
15
+ // How to make a method generic: declare <T> in its method signature
17
16
public static <T > void printArray_generic_type (T [] nums ) {
18
17
for (T i : nums ) {
19
18
System .out .print (i + ", " );
@@ -22,14 +21,19 @@ public static <T> void printArray_generic_type(T[] nums) {
22
21
}
23
22
24
23
public static void main (String ... strings ) {
25
- Integer [] nums = new Integer []{1 , 2 , 3 , 4 , 5 };
24
+ Integer [] nums = new Integer [] {1 , 2 , 3 , 4 , 5 };
26
25
printArray_generic_type (nums );
27
- String input1 = "[\" zDkA\" ,\" GfAj\" ,\" lt\" ],[\" GfAj\" ,\" rtupD\" ,\" og\" ,\" l\" ],[\" rtupD\" ,\" IT\" ,\" jGcew\" ,\" ZwFqF\" ],[\" og\" ,\" yVobt\" ,\" EjA\" ,\" piUyQ\" ],[\" IT\" ,\" XFlc\" ,\" W\" ,\" rB\" ],[\" l\" ,\" GwQg\" ,\" shco\" ,\" Dub\" ,\" KwgZq\" ],[\" oXMG\" ,\" uqe\" ],[\" sNyV\" ,\" WbrP\" ]" ;
26
+ String input1 =
27
+ "[\" zDkA\" ,\" GfAj\" ,\" lt\" ],[\" GfAj\" ,\" rtupD\" ,\" og\" ,\" l\" ],[\" rtupD\" ,\" IT\" ,\" jGcew\" ,\" ZwFqF\" ],[\" og\" ,\" yVobt\" ,\" EjA\" ,\" piUyQ\" ],[\" IT\" ,\" XFlc\" ,\" W\" ,\" rB\" ],[\" l\" ,\" GwQg\" ,\" shco\" ,\" Dub\" ,\" KwgZq\" ],[\" oXMG\" ,\" uqe\" ],[\" sNyV\" ,\" WbrP\" ]" ;
28
28
String input2 = "[\" A\" ,\" B\" ],[\" C\" ],[\" B\" ,\" C\" ],[\" D\" ]" ;
29
29
CommonUtils .printListList (convertLeetCode2DStringArrayInputIntoJavaArray (input1 ));
30
30
CommonUtils .printListList (convertLeetCode2DStringArrayInputIntoJavaArray (input2 ));
31
- CommonUtils .print (convertLeetCode1DStringArrayInputIntoJavaArray ("[\" abcsi\" ,\" abyzjgj\" ,\" advz\" ,\" ag\" ,\" agkgdkob\" ,\" agpr\" ,\" ail\" ]" ));
32
- CommonUtils .print2DIntArray (convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray ("[448,931,123,345],[889],[214,962],[576,746,897]" ));
31
+ CommonUtils .print (
32
+ convertLeetCode1DStringArrayInputIntoJavaArray (
33
+ "[\" abcsi\" ,\" abyzjgj\" ,\" advz\" ,\" ag\" ,\" agkgdkob\" ,\" agpr\" ,\" ail\" ]" ));
34
+ CommonUtils .print2DIntArray (
35
+ convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray (
36
+ "[448,931,123,345],[889],[214,962],[576,746,897]" ));
33
37
}
34
38
35
39
public static void printArray (boolean [] booleans ) {
@@ -98,8 +102,8 @@ public static List<Integer> randomIntArrayGenerator(int size) {
98
102
99
103
// overloaded method to take no argument
100
104
public static List <Integer > randomIntArrayGenerator () {
101
- return CommonUtils .randomIntArrayGenerator (CommonUtils . DEFAULT_TREE_SIZE ,
102
- DEFAULT_UPPER_BOUND );
105
+ return CommonUtils .randomIntArrayGenerator (
106
+ CommonUtils . DEFAULT_TREE_SIZE , DEFAULT_UPPER_BOUND );
103
107
}
104
108
105
109
// this one has two other overloaded methods as above
@@ -126,7 +130,8 @@ public static List<Integer> uniqueIntArrayGenerator(int size) {
126
130
}
127
131
128
132
// @Notes(context =
129
- // "I'm assuing only classes in this PACKAGE will call the following two methods, so just leave the modifier as default, i.e. no public, private, or protected.")
133
+ // "I'm assuing only classes in this PACKAGE will call the following two methods, so just leave
134
+ // the modifier as default, i.e. no public, private, or protected.")
130
135
public static void printWhitespaces (int count ) {
131
136
for (int i = 0 ; i < count ; i ++) {
132
137
System .out .print (" " );
@@ -143,7 +148,7 @@ public static <T> boolean isAllElementsNull(List<T> list) {
143
148
return true ;
144
149
}
145
150
146
- /**
151
+ /*
147
152
* If you want to print the reversed list out, you need to return the reversed list's head,
148
153
* which was the end node of the original node. using the following function.
149
154
*/
@@ -228,7 +233,6 @@ public static void printMatrixGeneric(boolean[][] matrix) {
228
233
System .out .println ();
229
234
}
230
235
System .out .println ("----------------------------------------------------" );
231
-
232
236
}
233
237
234
238
public static <T > void printListList (List <List <T >> res ) {
@@ -268,11 +272,11 @@ public static void print2DCharArray(char[][] arrayArrays) {
268
272
}
269
273
270
274
public static char [][] convertLeetCodeRegular2DCharArrayInputIntoJavaArray (String input ) {
271
- /* *LeetCode 2-d char array usually comes in like this:
272
- * ["#"," ","#"],[" "," ","#"],["#","c"," "] which is wrapped in double quotes instead of single quotes which makes it not usable in Java code.
273
- * This method helps with the conversion.*/
275
+ / *LeetCode 2-d char array usually comes in like this:
276
+ * ["#"," ","#"],[" "," ","#"],["#","c"," "] which is wrapped in double quotes instead of single quotes which makes it not usable in Java code.
277
+ * This method helps with the conversion.*/
274
278
String [] arrays = input .split ("],\\ [" );
275
- // CommonUtils.printArray_generic_type(arrays);
279
+ // CommonUtils.printArray_generic_type(arrays);
276
280
int m = arrays .length ;
277
281
int n = arrays [1 ].split ("," ).length ;
278
282
char [][] ans = new char [m ][n ];
@@ -300,15 +304,15 @@ public static char[][] convertLeetCodeRegular2DCharArrayInputIntoJavaArray(Strin
300
304
}
301
305
302
306
public static int [][] convertLeetCodeRegularRectangleArrayInputIntoJavaArray (String input ) {
303
- /**
307
+ /*
304
308
* LeetCode 2-d array input usually comes like this: it's a REGULAR rectangle
305
309
* [[448,931],[234,889],[214,962],[576,746]]
306
310
* The expected input for this method is: "[448,931],[234,889],[214,962],[576,746]"
307
311
* i.e. strip off the beginning and ending square brackets, that's it.
308
312
* The output of this method will be a standard Java 2-d array.
309
313
* */
310
314
String [] arrays = input .split ("],\\ [" );
311
- // CommonUtils.printArray_generic_type(arrays);
315
+ // CommonUtils.printArray_generic_type(arrays);
312
316
int size = arrays [1 ].split ("," ).length ;
313
317
int [][] output = new int [arrays .length ][size ];
314
318
for (int i = 0 ; i < arrays .length ; i ++) {
@@ -331,12 +335,12 @@ public static int[][] convertLeetCodeRegularRectangleArrayInputIntoJavaArray(Str
331
335
}
332
336
}
333
337
}
334
- // CommonUtils.print2DIntArray(output);
338
+ // CommonUtils.print2DIntArray(output);
335
339
return output ;
336
340
}
337
341
338
342
public static int [][] convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray (String input ) {
339
- /**
343
+ /*
340
344
* LeetCode 2-d array input usually comes like this: each row could have different length
341
345
* [[448,931,123,345],[889],[214,962],[576,746,897]]
342
346
* The expected input for this method is: "[448,931,123,345],[889],[214,962],[576,746,897]"
@@ -388,7 +392,7 @@ public static int[][] convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(S
388
392
}
389
393
390
394
public static List <List <String >> convertLeetCode2DStringArrayInputIntoJavaArray (String input ) {
391
- /**
395
+ /*
392
396
* How to copy LeetCode 2-d String array into this method:
393
397
* 1. remove the beginning and ending quotes;
394
398
* 2. put double quotes into this method parameter;
@@ -423,7 +427,7 @@ public static List<List<String>> convertLeetCode2DStringArrayInputIntoJavaArray(
423
427
}
424
428
425
429
public static List <String > convertLeetCode1DStringArrayInputIntoJavaArray (String input ) {
426
- /**
430
+ /*
427
431
* LeetCode 2-d array input usually comes like this: each row could have different length
428
432
* ["A","B","C"]
429
433
* The expected input for this method is: "[\"A\",\"B\",\"C\"]"
0 commit comments