Skip to content

Commit 802695a

Browse files
author
chenweijie
committed
求树的最大和最小深度
1 parent 1835ab1 commit 802695a

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.chen.algorithm.study.test144;
2+
3+
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
7+
/**
8+
* @author : chen weijie
9+
* @Date: 2020-05-11 23:21
10+
*/
11+
public class Solution1 {
12+
13+
public class TreeNode {
14+
int val;
15+
TreeNode left;
16+
TreeNode right;
17+
18+
TreeNode(int x) {
19+
val = x;
20+
}
21+
}
22+
23+
public List<Integer> preorderTraversal(TreeNode root) {
24+
List<Integer> res = new ArrayList<>();
25+
26+
if (root == null) {
27+
return res;
28+
}
29+
30+
res.add(root.val);
31+
preorderTraversal(root.left);
32+
preorderTraversal(root.right);
33+
34+
return res;
35+
}
36+
37+
}

src/main/java/com/chen/algorithm/study/test94/Solution.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ class TreeNode {
2020
}
2121
}
2222

23-
List<Integer> result = new ArrayList<>();
2423

2524
public List<Integer> inorderTraversal(TreeNode root) {
26-
25+
List<Integer> result = new ArrayList<>();
2726

2827
if (root == null) {
2928
return result;

0 commit comments

Comments
 (0)