【二叉树的递归】02二叉树的最大深度【Maximum Depth of Binary Tree】
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
给定一个二叉树,找出他的最小的深度。
最小的深度,指的是从根节点到叶子节点的,经历的最多的节点个数。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
test.cpp:
|
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
#include <iostream>
#include <cstdio> #include <stack> #include <vector> #include <queue> #include "BinaryTree.h" using namespace std; int maxDepth(TreeNode *root) if(tmp->left != NULL) // 树中结点含有分叉, ConnectTreeNodes(pNodeA1, pNodeA2, pNodeA3); cout << maxDepth(pNodeA1) << endl; DestroyTree(pNodeA1); |
|
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#ifndef _BINARY_TREE_H_
#define _BINARY_TREE_H_ struct TreeNode TreeNode *CreateBinaryTreeNode(int value); #endif /*_BINARY_TREE_H_*/ |
|
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
#include <iostream>
#include <cstdio> #include "BinaryTree.h" using namespace std; /** //创建结点 return pNode; //连接结点 //打印节点内容以及左右子结点内容 if(pNode->left != NULL) if(pNode->right != NULL) printf("\n"); //前序遍历递归方法打印结点内容 if(pRoot != NULL) if(pRoot->right != NULL) void DestroyTree(TreeNode *pRoot) delete pRoot; DestroyTree(pLeft); |
【二叉树的递归】02二叉树的最大深度【Maximum Depth of Binary Tree】的更多相关文章
- LeetCode 104. 二叉树的最大深度(Maximum Depth of Binary Tree)
104. 二叉树的最大深度 104. Maximum Depth of Binary Tree 题目描述 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说 ...
- [Swift]LeetCode104. 二叉树的最大深度 | Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- [LintCode] Maximum Depth of Binary Tree 二叉树的最大深度
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- leetcode 104 Maximum Depth of Binary Tree二叉树求深度
Maximum Depth of Binary Tree Total Accepted: 63668 Total Submissions: 141121 My Submissions Question ...
- 104. Maximum Depth of Binary Tree(C++)
104. Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is ...
- LeetCode:Minimum Depth of Binary Tree,Maximum Depth of Binary Tree
LeetCode:Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth ...
- 【LeetCode练习题】Maximum Depth of Binary Tree
Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the n ...
- [Leetcode][JAVA] Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree
Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...
- LeetCode Javascript实现 258. Add Digits 104. Maximum Depth of Binary Tree 226. Invert Binary Tree
258. Add Digits Digit root 数根问题 /** * @param {number} num * @return {number} */ var addDigits = func ...
- 【LeetCode】104. Maximum Depth of Binary Tree (2 solutions)
Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the ...
随机推荐
- Django安装和启动
1.django安装 在http://www.djangoproject.com/download/这个网站上可以下载django的最新版本.在下载时,要注意django版本和本机安装的Python版 ...
- 承载(Host)通用语言执行时
承载(Host)通用语言执行时(CLR) 还有一种使用COM 的方法是是把须要集成的 F# 代码与已有的 C/C++ 应用程序集成到一起.开成自己定义的承载通用语言执行时.通用语言执行时就是 C++ ...
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- SQLServer判断一个IP是否在一个IP段里
declare @ip1 varchar(20)declare @ip2 varchar(20)set @ip1='221.231.138.101'set @ip2='255.255.255.255' ...
- 我的Android进阶之旅------>Android中AsyncTask源码分析
在我的<我的Android进阶之旅------>android异步加载图片显示,并且对图片进行缓存实例>文章中,先后使用了Handler和AsyncTask两种方式实现异步任务机制. ...
- Open AI Gym简介
介绍 OpenAI Gym是一款用于研发和比较强化学习算法的工具包,它支持训练智能体(agent)做任何事——从行走到玩Pong或围棋之类的游戏都在范围中. OpenAI Gym 是一个用于开发和比较 ...
- java面向对象入门之方法参数的传递
/* Name : Power by :Stuart Date:2015.4.25 */ class PassOn{ //创建show方法,把i传入,输出i+1的结果 public void show ...
- Android app与PC端交互
app提交信息到PC端mysql数据库 新建名为SignActivity package com.example.administrator.success; import android.app.A ...
- mysql主从复制(windows下)
简单搭建mysql主从服务器(双向复制),仅供学习之用. 1.下载mysql-advanced-5.6.16-winx64.zip 下载完成后解压,重命名成mysql,分别放入两台服务器(看第二点集群 ...
- PAT 天梯赛 L2-009. 抢红包 【排序】
题目链接 https://www.patest.cn/contests/gplt/L2-009 思路 用结构体存储,然后结构体排序 注意一下 个人编号是从 1 开始 计数的 AC代码 #include ...