111. 二叉树的最小深度

 1 /**
 2  * Definition for a binary tree node.
 3  * public class TreeNode {
 4  *     int val;
 5  *     TreeNode left;
 6  *     TreeNode right;
 7  *     TreeNode(int x) { val = x; }
 8  * }
 9  */
10 class Solution {
11     public int minDepth(TreeNode root) {
12         if(root==null)
13             return 0;
14         if(root.left==null)
15             return minDepth(root.right)+1;
16         if(root.right==null)
17             return minDepth(root.left)+1;
18         return Math.min(minDepth(root.left),minDepth(root.right))+1;
19         
20     }
21 }

题目链接:

https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/submissions/

解题思路:

原文地址:https://www.cnblogs.com/wangyufeiaichiyu/p/11244225.html