1.题目描述 2.问题分析 利用递归fangf 3.代码 int maxDepth(Node* root) { int res = maxdep(root); return res; } int maxdep(Node *root) { if (root == NULL) ; else { ; for (auto child : root->children) { res = max(res,maxdep(child)+); } return res; } }…
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 来源:https://leetcode.com/problems/maximum-depth-of-binary-tree/ Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along th…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:BFS 方法二:DFS 参考资料 日期 题目地址:https://leetcode.com/problems/maximum-depth-of-binary-tree/ Total Accepted: 85334 Total Submissions: 188240 Difficulty: Easy 题目描述 Given a binary tr…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS BFS 日期 题目地址:https://leetcode.com/problems/maximum-depth-of-n-ary-tree/description/ 题目描述 Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes…
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. Solution: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNo…
The problem 1: 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. My analysis: The recursion solution for this problem is very elegant!It inc…
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. 求二叉树的高度,即从根节点到叶节点上所有节点的数量. 解题思路: 这题是难度系数1,频率1的题目……用到的知识点是二叉树D…
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. 很简单,直接上代码: /** * Definition for a binary tree node. * public class TreeNode { * int val; *…
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. 与Minimum Depth of Binary Tree对照看 解法一:递归,子树高度+1. /** * Defini…
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. 求二叉树深度,直接看代码: /** * Definition for a binary tree node. * struct TreeNode { * int val; * Tr…