-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild123.java
More file actions
50 lines (37 loc) · 883 Bytes
/
build123.java
File metadata and controls
50 lines (37 loc) · 883 Bytes
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
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) { val = x; }
}
public void build123() {
TreeNode root = new TreeNode(2);
root.left = new TreeNode(1);
root.right = new TreeNode(3);
}
public int size(TreeNode root) {
if (root == null) return 0;
int size = 1;
while (root.left != null || roo.right != null) {
size += size(left) + size(right);
}
return size;
}
public int maxDepth(TreeNode root) {
if (root == null) return 0;
int depth = 1;
while (root.left != null || root.right != null) {
depth += maxDepth(maxDepth(root.left), maxDepth(root.right));
}
return depth;
}
public int minValue(TreeNode root) {
if (root == null) return null;
TreeNode current = root;
while (current.left != null) {
current = current.left
}
return current.val;
}
public TreeNode printTree(TreeNode root) {
}