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.

Note: A leaf is a node with no children.

Example:

Given binary tree [3,9,20,null,null,15,7],

    3
/ \
9 20
/ \
15 7

return its depth = 3.

/**
* 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 ; return max(maxDepth(root->left), maxDepth(root->right)) + ;
}
};

最新文章

  1. [leetcode] 数字游戏
  2. 关于PetaPoco的T4模板使用
  3. HTML5 history API实践
  4. Delphi 过程与函数
  5. mysql创建用户和创建数据库赋值用户操作权限
  6. Linux有问必答:怎样解决“XXX is not in the sudoers file”错误
  7. Firefox插件一键切换兼容IE
  8. php数组声明、遍历、数组全局变量使用小结
  9. 转载:linux capability深入分析
  10. Adapter优化方案的探索
  11. 1. Server.Transfer和Response.Redirect
  12. 安装Eclipse Html Editor
  13. 【视频】零基础学Android开发:蓝牙聊天室APP(四)
  14. C#中的??是什么意思
  15. lldpd-0.7.7代码解读(send_pdu部分)
  16. phpcms2008常用函数小结
  17. Shopping List
  18. bcftools将vcf生成bgzip和index格式
  19. Hive shell 基本命令
  20. 关于var、let、const的故事

热门文章

  1. 如何在macOS下调整磁盘分区大小?
  2. 第五次个人作业- Alpha项目测试
  3. Educational Codeforces Round 65 (Rated for Div. 2)题解
  4. live555 基本框架
  5. Python基础知识笔记-作用域
  6. vue基于iview树状表格,封装完善
  7. WinDbg常用命令系列---!findstack
  8. uni app 零基础小白到项目实战2
  9. cloneable以及深拷贝和浅拷贝
  10. vs2017下载安装