第十六周:104. Maximum Depth of Binary Tree
来源:互联网 发布:ssh 客户端 for mac 编辑:程序博客网 时间:2024/06/10 04:56
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.
这道题一行代码就可以解决了,主要就是用到递归的思想。
AC:
/** * 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) { return root == NULL ? 0 : max(maxDepth(root -> left), maxDepth(root -> right)) + 1; }};
0 0
- 第十六周: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] 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
- PHP中isset()和empty()的使用
- Length of Last Word
- 数组指针和指针数组的理解
- FFMPEG deprecated 属性与is deprecated [-Wdeprecated-declarations] 警告
- Scrapy爬虫入门教程十三 Settings(设置)
- 第十六周:104. Maximum Depth of Binary Tree
- k均值聚类算法
- PHP:array_map函数使用
- [DB2]Linux下安装db2 v9.7
- Mysql 运维相关脚本收集
- matlab学习之一
- 运营新人写简历的9大注意事项
- Hdu 2896 病毒侵袭(AC自动机)
- 跨平台SSE、AVX指令测试