2017.11.5 LeetCode - 104. Maximum Depth of Binary Tree 【dfs的应用】
2017-11-06 18:32
323 查看
104. Maximum Depth of Binary Tree
Description
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.
题意: 求一颗二叉树的深度
分析: 直接dfs模拟即可
参考函数
class Solution { public: int res = 0; void dfs(TreeNode* root,int c) { if(!root) return ; res = max(res,c); dfs(root->left,c+1); dfs(root->right,c+1); } int maxDepth(TreeNode* root) { dfs(root,1); return res; } };
相关文章推荐
- leetcode dfs Convert Sorted List to Binary Search Tree
- leetcode 297. Serialize and Deserialize Binary Tree 二叉树的序列化和反序列化 + 深度优先遍历DFS
- leetcode dfs Validate Binary Search Tree
- leetcode 98. Validate Binary Search Tree DFS深度优先搜索 + 两个递归函数 + 一个错误做法
- leetcode 226. Invert Binary Tree 反转二叉树 + DFS深度优先搜索
- leetcode 236. Lowest Common Ancestor of a Binary Tree 最近公告祖先LCA + 二叉树 + 深度优先遍历DFS
- Leetcode dfs Construct Binary Tree from Preorder and Inorder Traversal
- LeetCode 104 Maximum Depth of Binary Tree(DFS)
- DFS的应用——Binary Tree Paths
- [leetcode] Validate Binary Search Tree dfs
- LeetCode 111 Minimum Depth of Binary Tree (DFS)
- [leetcode]Minimum Depth of Binary Tree--二叉树层序遍历的应用
- [LeetCode系列]卡特兰数(Catalan Number) 在求解独特二叉搜寻树(Unique Binary Search Tree)中的应用分析
- 【LeetCode】104. Maximum Depth of Binary Tree(DFS|BFS)
- leetcode dfs Minimum Depth of Binary Tree
- [DFS] leetcode 104. Maximum Depth of Binary Tree
- Leetcode dfs Construct Binary Tree from Inorder and Postorder Traversal
- [LeetCode系列]卡特兰数(Catalan Number) 在求解独特二叉搜寻树(Unique Binary Search Tree)中的应用分析
- 【Leetcode】110. Balanced Binary Tree 【DFS】
- LeetCode 606.[DFS] Construct String from Binary Tree