Leetcode Maximum Depth of Binary Tree
来源:互联网 发布:bilibili没有网络 编辑:程序博客网 时间:2024/05/29 17:42
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; int depth = 1; Depth(root,depth,1); return depth; } void Depth(TreeNode* root,int& depth,int count) { if(root == NULL) return; if(count > depth) depth = count; Depth(root->left,depth,count+1); Depth(root->right,depth,count+1); }};
阅读全文
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
- 令牌环网
- centOS7 装ghost如中的记录
- 关于 支持向量机 SVM很简单的理解
- 【HTTP】Fiddler(二)- 使用Fiddler做抓包分析
- Spring中ApplicationContext的使用说明
- Leetcode Maximum Depth of Binary Tree
- FPGA测试文件的生成和modelsim altera仿真器的关联
- QT 数字转字符串自动补0或者空格,arg()的用法
- 20170628在东软
- 台式机利用独立显卡连接两个显示器
- XML的CDATA区域(无视特殊字符,一般用在需要多处处理转义的语句中)
- AMD规范中模块id的命名规则
- adb 连接报错信息adb已停止运行
- 数据链路层MAC帧校验——CRC