5.4.1—二叉树的递归—Minimum Depth of Binary Tree
来源:互联网 发布:mmd双人动作数据 编辑:程序博客网 时间:2024/06/05 09:09
描述
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.
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.
#include "BinaryTree.h"#include<vector>using namespace std;//===求一棵二叉树的最小深度int MinDepth(BinaryTreeNode *proot){if (proot == NULL) return 0;if (!proot->m_pLeft&&!proot->m_pRight) return 1;if (!proot->m_pLeft&&proot->m_pRight) return 1;if (proot->m_pLeft&&!proot->m_pRight) return 1;return MinDepth(proot->m_pLeft) < MinDepth(proot->m_pRight) ? 1+MinDepth(proot->m_pLeft) : 1+MinDepth(proot->m_pRight);}// ====================测试代码====================// 8// 6 10// 5 7 9 11int main(){//===BinaryTreeNode* pNode8 = CreateBinaryTreeNode(8);BinaryTreeNode* pNode6 = CreateBinaryTreeNode(6);BinaryTreeNode* pNode10 = CreateBinaryTreeNode(10);BinaryTreeNode* pNode5 = CreateBinaryTreeNode(5);BinaryTreeNode* pNode7 = CreateBinaryTreeNode(7);BinaryTreeNode* pNode9 = CreateBinaryTreeNode(9);BinaryTreeNode* pNode11 = CreateBinaryTreeNode(11);ConnectTreeNodes(pNode8, pNode6, pNode10);ConnectTreeNodes(pNode6, pNode5, pNode7);ConnectTreeNodes(pNode10, pNode9, pNode11);//===//PrintTree(pNode8);//===int mindepth = MinDepth(pNode8);cout << mindepth << endl;DestroyTree(pNode8);}
阅读全文
0 0
- 5.4.1—二叉树的递归—Minimum Depth of Binary Tree
- 5.4.2—二叉树的递归—Maximum Depth of Binary Tree
- Minimum Depth of Binary Tree 二叉树的最小深度
- Minimum Depth of Binary Tree 二叉树的最小深度
- Minimum Depth of Binary Tree 二叉树的最小深度
- 5.4.1 Minimum Depth of Binary Tree
- 5.4.1 Minimum Depth of Binary Tree
- LeetCode111—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 二叉树最小深度
- 二叉树遍历111. Minimum Depth of Binary Tree
- LeetCode:minimum-depth-of-binary-tree(二叉树最小深度)
- 【二叉树】111. Minimum Depth of Binary Tree
- 【二叉树】计算二叉树深度【104. Maximum Depth of Binary Tree】【111. Minimum Depth of Binary Tree】
- 求二叉树的最小深度 Minimum Depth of Binary Tree
- LeetCode(Minimum Depth of Binary Tree) 二叉树的最低高度
- 5.3.5—二叉查找树—Convert Sorted List to Binary Sear Tree
- 动态规划中级教程 343. Integer Break
- 大型复杂信息系统研发的大学式组织管理方法
- UVA11754 Code Feat
- 坦克大战学习笔记
- 5.4.1—二叉树的递归—Minimum Depth of Binary Tree
- opencv获取彩色(RGB)图像直方图
- Oracle SQL语句优化
- docker学习笔记--重基础使用
- Wireshark图解教程(简介、抓包、过滤器)
- 5.4.2—二叉树的递归—Maximum Depth of Binary Tree
- 使用正则表达式控制input框输入类型
- 5.4.3—二叉树的递归—Path Sum
- 一流大学 VS. 工业部门