LeetCode #104 Maximum Depth of Binary Tree
来源:互联网 发布:日剧知乎 编辑:程序博客网 时间:2024/05/16 12:28
#104 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.
Solution:
/** * 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 { int left = maxDepth(root -> left); //A recursion int right = maxDepth(root -> right); return max(left,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: 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
- leetcode-104-Maximum Depth of Binary Tree
- Leetcode #104 Maximum Depth of Binary Tree
- leetcode 104: Maximum Depth of Binary Tree
- Struts2学习笔记(一)
- iOS 9 适配系列教程
- 各种优化方法总结比较(sgd/momentum/Nesterov/adagrad/adadelta)
- 食物中毒
- FFMpeg调通PC端查看Android摄像头数据
- LeetCode #104 Maximum Depth of Binary Tree
- TabLayout+viewpager构成主流软件界面
- MSYS的下载与安装
- 三万多人的阿里如何做好研发管理?秘密就在阿里持续交付
- 使用两台Kinect2.0和ipi studio进行动作捕捉
- PHP与AJAX的简单使用
- Educational Codeforces Round 5 (D. Longest k-Good Segment)(尺取法)
- HDOJ 2082 找单词(母函数模板题)
- 51nod1081 子段求和(dp、树状数组、线段树求法)