104. Maximum Depth of Binary Tree
来源:互联网 发布:程序怎么变成软件 编辑:程序博客网 时间:2024/06/07 23:18
T
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.
S
/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ int maxDep(struct TreeNode *root, int m) { if (root == NULL) { return m; } ++m; int l = maxDep(root->left, m;) int r = maxDep(root->right, m); return (l>r?l:r); }int maxDepth(struct TreeNode* root) { if (root == NULL) { return 0; } int m = 0; return maxDep(root, m);}
/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */int maxDepth(struct TreeNode* root) { if (root == NULL) { return 0; } int l = maxDepth(root->left); int r = maxDepth(root->right); return (l>r?l:r) + 1;}
0 0
- [LeetCode]104.Maximum Depth of Binary Tree
- 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
- 104.Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- 104.Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- leetCode 104. Maximum Depth of Binary Tree
- 104. Maximum Depth of Binary Tree
- 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
- 记录文本框内容的动态变化
- bootstrap_fileinput 上传组件的简单使用
- Android 系列 1.4学习Java语言
- 今天提示MyEclipse Trial Expired,如何手动获取MyEclipse 注册码!很牛!
- PyQt5学习随笔
- 104. Maximum Depth of Binary Tree
- jquery插件开发2之function( $, window, document, undefined ){}的理解
- android 解决底部navigation与手机虚拟按键重叠问题
- Vuejs——(1)入门(单向绑定、双向绑定、列表渲染、响应函数)
- 【Java基础知识】IO流--File类和路径分隔符
- RxJava进阶01
- JBOSS在windows下的环境配置和启动时遇到的错误
- Android 系列 1.5从命令行创建“Hello,World”应用程序
- 局部变量&&malloc函数&&生命周期的一些见解