22
33import com .fishercoder .common .classes .Interval ;
44import com .fishercoder .common .classes .ListNode ;
5-
65import java .util .ArrayList ;
76import java .util .Deque ;
87import java .util .List ;
@@ -13,7 +12,7 @@ public class CommonUtils {
1312 private static final int DEFAULT_TREE_SIZE = 10 ;
1413 private static final int DEFAULT_UPPER_BOUND = 100 ;
1514
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
1716 public static <T > void printArray_generic_type (T [] nums ) {
1817 for (T i : nums ) {
1918 System .out .print (i + ", " );
@@ -22,14 +21,19 @@ public static <T> void printArray_generic_type(T[] nums) {
2221 }
2322
2423 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 };
2625 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\" ]" ;
2828 String input2 = "[\" A\" ,\" B\" ],[\" C\" ],[\" B\" ,\" C\" ],[\" D\" ]" ;
2929 CommonUtils .printListList (convertLeetCode2DStringArrayInputIntoJavaArray (input1 ));
3030 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]" ));
3337 }
3438
3539 public static void printArray (boolean [] booleans ) {
@@ -98,8 +102,8 @@ public static List<Integer> randomIntArrayGenerator(int size) {
98102
99103 // overloaded method to take no argument
100104 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 );
103107 }
104108
105109 // this one has two other overloaded methods as above
@@ -126,7 +130,8 @@ public static List<Integer> uniqueIntArrayGenerator(int size) {
126130 }
127131
128132 // @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.")
130135 public static void printWhitespaces (int count ) {
131136 for (int i = 0 ; i < count ; i ++) {
132137 System .out .print (" " );
@@ -143,7 +148,7 @@ public static <T> boolean isAllElementsNull(List<T> list) {
143148 return true ;
144149 }
145150
146- /**
151+ /*
147152 * If you want to print the reversed list out, you need to return the reversed list's head,
148153 * which was the end node of the original node. using the following function.
149154 */
@@ -228,7 +233,6 @@ public static void printMatrixGeneric(boolean[][] matrix) {
228233 System .out .println ();
229234 }
230235 System .out .println ("----------------------------------------------------" );
231-
232236 }
233237
234238 public static <T > void printListList (List <List <T >> res ) {
@@ -268,11 +272,11 @@ public static void print2DCharArray(char[][] arrayArrays) {
268272 }
269273
270274 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.*/
274278 String [] arrays = input .split ("],\\ [" );
275- // CommonUtils.printArray_generic_type(arrays);
279+ // CommonUtils.printArray_generic_type(arrays);
276280 int m = arrays .length ;
277281 int n = arrays [1 ].split ("," ).length ;
278282 char [][] ans = new char [m ][n ];
@@ -300,15 +304,15 @@ public static char[][] convertLeetCodeRegular2DCharArrayInputIntoJavaArray(Strin
300304 }
301305
302306 public static int [][] convertLeetCodeRegularRectangleArrayInputIntoJavaArray (String input ) {
303- /**
307+ /*
304308 * LeetCode 2-d array input usually comes like this: it's a REGULAR rectangle
305309 * [[448,931],[234,889],[214,962],[576,746]]
306310 * The expected input for this method is: "[448,931],[234,889],[214,962],[576,746]"
307311 * i.e. strip off the beginning and ending square brackets, that's it.
308312 * The output of this method will be a standard Java 2-d array.
309313 * */
310314 String [] arrays = input .split ("],\\ [" );
311- // CommonUtils.printArray_generic_type(arrays);
315+ // CommonUtils.printArray_generic_type(arrays);
312316 int size = arrays [1 ].split ("," ).length ;
313317 int [][] output = new int [arrays .length ][size ];
314318 for (int i = 0 ; i < arrays .length ; i ++) {
@@ -331,12 +335,12 @@ public static int[][] convertLeetCodeRegularRectangleArrayInputIntoJavaArray(Str
331335 }
332336 }
333337 }
334- // CommonUtils.print2DIntArray(output);
338+ // CommonUtils.print2DIntArray(output);
335339 return output ;
336340 }
337341
338342 public static int [][] convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray (String input ) {
339- /**
343+ /*
340344 * LeetCode 2-d array input usually comes like this: each row could have different length
341345 * [[448,931,123,345],[889],[214,962],[576,746,897]]
342346 * 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
388392 }
389393
390394 public static List <List <String >> convertLeetCode2DStringArrayInputIntoJavaArray (String input ) {
391- /**
395+ /*
392396 * How to copy LeetCode 2-d String array into this method:
393397 * 1. remove the beginning and ending quotes;
394398 * 2. put double quotes into this method parameter;
@@ -423,7 +427,7 @@ public static List<List<String>> convertLeetCode2DStringArrayInputIntoJavaArray(
423427 }
424428
425429 public static List <String > convertLeetCode1DStringArrayInputIntoJavaArray (String input ) {
426- /**
430+ /*
427431 * LeetCode 2-d array input usually comes like this: each row could have different length
428432 * ["A","B","C"]
429433 * The expected input for this method is: "[\"A\",\"B\",\"C\"]"
0 commit comments