【leetcode】: Maximum Depth of Binary Tree
来源:互联网 发布:地产网络推广公司排名 编辑:程序博客网 时间:2024/05/17 08:09
前言
菜的抠脚的一道题,求一个二叉树的最深深度,就是数据结构与算法上面的一道非常简单的题….
思路
通过对左右孩子进行递归求出最深深度…见代码即可
/** * 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 l = maxDepth(root->left); int r = maxDepth(root->right); return l>r?l+1:r+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
- 设计模式
- Android定制化显示toast
- git克隆;上传;合并
- setFixedSize引起video画面闪烁
- 基于Elasticsearch+Fluentd+Kibana的日志收集分析系统搭建与应用
- 【leetcode】: Maximum Depth of Binary Tree
- Android的菜单资源
- Filter拦截器压缩全网站数据
- 设计模式-建造者模式
- 令牌桶算法和漏桶算法
- Android夜间模式最佳实践
- Silverlight 应用程序中未处理的错误 代码: 2104 类别:
- CSS学习笔记4-值与单位
- [软件人生]关于同行竞业,你需要知道,你需要关注后续