LeetCode---Maximum Depth of Binary Tree
来源:互联网 发布:软件企业财务处理 编辑:程序博客网 时间:2024/05/10 02:09
题目大意:给出一个二叉树,求出该二叉树的最大深度。最大深度是指从根节点沿着最长路径到叶子节点的节点数。
算法思想:
采用递归遍历二叉树的方法,求出其左右子树的最大深度+1.
代码如下:
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: int maxDepth(TreeNode* root) { if(root==NULL) return 0; else return 1+max(maxDepth(root->left),maxDepth(root->right)); }};
0 0
- Leetcode - Tree - Maximum Depth of Binary Tree
- [leetcode][tree] Maximum Depth of Binary Tree
- LeetCode Maximum Depth of Binary Tree
- [Leetcode] Maximum Depth of Binary Tree
- leetcode 24: Maximum Depth of Binary Tree
- [LeetCode] Maximum Depth of Binary Tree
- Leetcode 104 Maximum Depth of Binary Tree
- 【leetcode】Maximum Depth of Binary Tree
- [leetcode]Maximum Depth of Binary Tree
- [LeetCode]Maximum Depth of Binary Tree
- [leetcode]Maximum Depth of Binary Tree
- Leetcode: Maximum Depth of Binary Tree
- LeetCode-Maximum Depth of Binary Tree
- [leetcode] Maximum Depth of Binary Tree
- LeetCode - Maximum Depth of Binary Tree
- LeetCode:Maximum Depth of Binary Tree
- LeetCode | Maximum Depth of Binary Tree
- 【leetcode】Maximum Depth of Binary Tree
- 职场准备(一)
- JS有参函数的创建和调用
- 皮尔逊相关系数评价算法(集体智慧编程)
- 有关紧性的几个定理
- 二维数组与指针的探索
- LeetCode---Maximum Depth of Binary Tree
- 近年来作品整理——杂
- 【bzoj1034】【zjoi2008】【泡泡堂】【贪心】
- android 点击按钮更换图片
- 本地保存List(Map(String, String))数据及JSON的一些用法
- 虚函数
- 如何制造一个XcodeGhost ?
- JDBC程序访问数据库的步骤
- 找出字符串中第一个只出现一次的字符