leetcode 二叉树的最小深度
来源:互联网 发布:正版bim软件多少钱 编辑:程序博客网 时间:2024/06/11 01:44
二叉树的最小深度定义: 根节点到叶子节点的最短距离。 叶子节点:左节点和右节点都为null。
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public int minDepth(TreeNode node) { if(node == null) return 0; if(node.left == null) return minDepth(node.right)+1; if(node.right == null) return minDepth(node.left)+1; return Math.min(minDepth(node.left),minDepth(node.right))+1; }}
0 0
- LeetCode 二叉树的最小深度
- leetcode 二叉树的最小深度
- LeetCode:寻找二叉树的最小深度
- leetcode 二叉树最小深度
- LeetCode—二叉树的最大最小深度
- leetcode 111-二叉树最小深度
- 二叉树的最小深度
- 二叉树的最小深度
- 二叉树的最小深度
- 二叉树的最小深度
- 二叉树的最小深度
- 二叉树的最小深度
- 二叉树的最小深度
- 二叉树的最小深度
- 二叉树的最小深度
- 二叉树的最小深度
- 二叉树的最小深度
- 二叉树的最小深度
- react学习之redux(四)
- hdu 1010 Tempter of the Bone(DFS+奇偶性剪枝)
- 项目实际运用中用到spring的什么功能?
- 欢迎使用CSDN-markdown编辑器
- 关于友善之臂Tiny210电容屏移植tslib
- leetcode 二叉树的最小深度
- [DP 容斥] BZOJ 2669 [cqoi2012]局部极小值
- Fragment与Activity的通信:
- JavaScript中那些折磨人的面试题
- js基础的重要性
- English Daily - August 8,2016-Letty
- BP神经网络的C++代码实现
- 未能加载文件或程序集"Microsoft.Web.Infrastructure 的解决方案
- CSS固定背景的图片