File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
src/main/java/algorithm/leetcode Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 6464| 105 | 树、深度优先搜索 | [ 从前序与中序遍历序列构造二叉树] ( src/main/java/algorithm/leetcode/Solution105.java ) | 中等 |
6565| 106 | 树、深度优先搜索 | [ 从中序与后序遍历序列构造二叉树] ( src/main/java/algorithm/leetcode/Solution106.java ) | 中等 |
6666| 107 | 树、广度优先搜索 | [ 二叉树的层次遍历 II] ( src/main/java/algorithm/leetcode/Solution107.java ) | 简单 |
67+ | 111 | 树、广度优先搜索、深度优先搜索 | [ 二叉树的最小深度] ( src/main/java/algorithm/leetcode/Solution111.java ) | 简单 |
6768| 120 | 数组、动态规划 | [ 三角形最小路径和] ( src/main/java/algorithm/leetcode/Solution120.java ) | 中等 |
6869| 121 | 数组、动态规划 | [ 买卖股票的最佳时机] ( src/main/java/algorithm/leetcode/Solution121.java ) | 简单 |
6970| 122 | 贪心算法、数组 | [ 买卖股票的最佳时机 II] ( src/main/java/algorithm/leetcode/Solution122.java ) | 简单 |
Original file line number Diff line number Diff line change 1+ package algorithm .leetcode ;
2+
3+ /**
4+ * @author: mayuan
5+ * @desc: 二叉树的最小深度
6+ * @date: 2019/03/07
7+ */
8+ public class Solution111 {
9+
10+ public int minDepth (TreeNode root ) {
11+ if (null == root ) {
12+ return 0 ;
13+ }
14+
15+ int l = minDepth (root .left );
16+ int r = minDepth (root .right );
17+
18+ if (0 == l || 0 == r ) {
19+ return l + r + 1 ;
20+ } else {
21+ return Math .min (l , r ) + 1 ;
22+ }
23+ }
24+
25+ class TreeNode {
26+ int val ;
27+ TreeNode left ;
28+ TreeNode right ;
29+
30+ TreeNode (int x ) {
31+ val = x ;
32+ }
33+ }
34+
35+ }
You can’t perform that action at this time.
0 commit comments