[LeetCode]104. Maximum Depth of Binary Tree
来源:互联网 发布:多益网络策划笔试题目 编辑:程序博客网 时间:2024/06/06 08:58
[LeetCode]104. Maximum Depth of Binary Tree
题目描述
思路
深搜,节点为NULL返回0,其余比较左右子树大小,返回大值
代码
/** * 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) return 0; int left = 1 + maxDepth(root->left); int right = 1 + maxDepth(root->right); return left > right ? left : right; }};
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
- 104. Maximum Depth of Binary Tree LeetCode
- 104. Maximum Depth of Binary Tree LeetCode
- 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
- 37.数字在排序数组中出现的次数
- 两种常用的字符串的比较方法
- Python3如何支持中文
- js学习之javascript引用类型object--练习模拟Map和数组去重
- 用Lucene创建索引
- [LeetCode]104. Maximum Depth of Binary Tree
- JSP+Servlet实现简单的用户登录注册
- Python中的super用法详解
- 漫谈cup、硬盘、内存和指针的关系
- leetcode_9. Palindrome Number
- 常用排序方法代码
- Java命令打包的依赖libs的解决
- hadoop数据上传hdfs出错
- ThreeJS 入门教程