leetcode:104 Maximum Depth of Binary Tree-每日编程第三题
来源:互联网 发布:2016淘宝睡衣模特红人 编辑:程序博客网 时间:2024/05/24 15:36
Maximum Depth of Binary Tree
Total Accepted: 105659 Total Submissions: 227723 Difficulty: Easy
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; * 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 max(maxDepth(root->left),maxDepth(root->right))+1; } }};
0 0
- leetcode:104 Maximum Depth of Binary Tree-每日编程第三题
- 【leetcode每日一题】104.Maximum Depth of Binary Tree
- leetcode 每日一题 104. Maximum Depth of Binary Tree
- Leetcode 104 Maximum Depth of Binary Tree
- LeetCode(104)Maximum Depth of Binary Tree
- LeetCode 104 Maximum Depth of Binary Tree
- LeetCode: Maximum Depth of Binary Tree [104]
- Leetcode(104)Maximum Depth of Binary Tree
- [leetcode 104] Maximum Depth of Binary Tree
- LeetCode 104 Maximum Depth of Binary Tree
- leetCode #104 Maximum Depth of Binary Tree
- LeetCode 104: Maximum Depth of Binary Tree
- LeetCode 104 Maximum Depth of Binary Tree
- leetcode || 104、Maximum Depth of Binary Tree
- LeetCode 104: Maximum Depth of Binary Tree
- leetcode[104]:Maximum Depth of Binary Tree
- Leetcode[104]-Maximum Depth of Binary Tree
- Leetcode---(104)Maximum Depth of Binary Tree
- OC-024.OC中多对象的手动内存管理
- Linux学习笔记(二) - sort,uniq,cut,wc 命令详解
- (java)Pascal's Triangle II
- 【剑指offer】之连续子数组的最大和
- 安装完CentOS 7 后必做的七件事
- leetcode:104 Maximum Depth of Binary Tree-每日编程第三题
- BOM与DOM简介
- 解决方案:Jboss修改jsp需要重启才生效
- Ubuntu 安装 wireshark
- 剑指offer系列之二十八:最小的k个数
- ubuntu14.04管理员密码忘记的解决方法
- leetcode:237 Delete Node in a Linked List-每日编程第四题
- 使用SimpleXML 处理XML 文件
- Eclipse最最最常用的快捷键