-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUtils.java
More file actions
71 lines (58 loc) · 1.68 KB
/
Utils.java
File metadata and controls
71 lines (58 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package utils;
import java.io.Serializable;
import java.util.List;
public class Utils {
private Utils() {
}
public static void printListInString(List<? extends Serializable> list) {
list.forEach(System.out::print);
System.out.println();
}
public static <T> void printIntArray(T[] arr) {
for (T element : arr) {
System.out.print(element + " ");
}
System.out.println();
}
public static void printIntArray(int[] arr) {
for (int element : arr) {
System.out.print(element + " ");
}
System.out.println();
}
public static void printIntArray(boolean[] arr) {
for (boolean element : arr) {
System.out.print(element + " ");
}
System.out.println();
}
public static void printIntArrayMonospace(int[] ints) {
for (int anInt : ints) {
System.out.printf("%3d", anInt);
}
System.out.println();
}
public static void printMatrix(int[][] matrix) {
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix.length; j++) {
System.out.printf("%2d", matrix[i][j]);
}
System.out.println();
}
}
public static void printBinaryTree(TreeNode node) {
if (node == null) {
return;
}
System.out.printf("%4d", node.val);
printBinaryTree(node.left);
printBinaryTree(node.right);
}
public static void printNodeList(ListNode node) {
while (node != null) {
System.out.print(node.val + " ");
node = node.next;
}
System.out.println();
}
}