Minimum Depth of Binary Tree 二叉树的最小深度
来源:互联网 发布:ultrawebgrid绑定数据 编辑:程序博客网 时间:2024/05/20 00:38
Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.
The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ //注意是叶子节点,左右都为空的节点才是class Solution {public: int minDepth(TreeNode *root) { if(root==NULL) return 0; if(root->left==NULL && root->right==NULL) return 1; int leftDep,rightDep; leftDep=minDepth(root->left); rightDep=minDepth(root->right); if(leftDep==0) return rightDep+1; else if(rightDep==0) return leftDep+1; return (leftDep<rightDep?leftDep:rightDep)+1; }};
0 0
- Minimum Depth of Binary Tree 二叉树的最小深度
- Minimum Depth of Binary Tree 二叉树的最小深度
- Minimum Depth of Binary Tree 二叉树的最小深度
- LeetCode Minimum Depth of Binary Tree 最小深度二叉树
- Minimum Depth of Binary Tree 二叉树最小深度
- Leetcode Minimum Depth of Binary Tree 二叉树最小深度
- lintcode minimum-depth-of-binary-tree 二叉树最小深度
- LeetCode:minimum-depth-of-binary-tree(二叉树最小深度)
- 求二叉树的最小深度 Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree -- 二叉树的最小深度 DFS 加剪枝
- LeetCode OJ 之 Minimum Depth of Binary Tree(二叉树的最小深度)
- [Java代码] [Leetcode] Maximum and Minimum Depth of Binary Tree 二叉树的最小最大深度
- 111. Minimum Depth of Binary Tree 二叉树的最小深度
- 111. Minimum Depth of Binary Tree 二叉树的最小深度
- 155.Minimum Depth of Binary Tree-二叉树的最小深度(容易题)
- Minimum Depth of Binary Tree(求二叉树的最小深度)
- leetcode_111. Minimum Depth of Binary Tree 二叉树的最小深度
- [LeetCode]111. Minimum Depth of Binary Tree--二叉树的最小深度
- Coursera上Andrew Ng机器学习课程总结(一)
- Balanced Binary Tree 平衡二叉树的判断
- String to Integer
- [图像]摄像机标定(2) 张正友标定推导详解
- Thinkphp学习笔记
- Minimum Depth of Binary Tree 二叉树的最小深度
- JQuery学习笔记之一
- HDU 5196 DZY Loves Inversions(离线+线段树)
- Python列表 元组 和字典
- jQuery中的.bind()、.live()和.delegate()之间区别分析
- 【爱上Linux】第一课 Linux概述
- HTML块
- Linux的经典文本编辑器vi的使用,基本的文件内容查看命令
- 在WinDBG中查看函数的反汇编代码的命令