Chinaunix首页 | 论坛 | 博客
  • 博客访问: 117339
  • 博文数量: 53
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 620
  • 用 户 组: 普通用户
  • 注册时间: 2014-08-24 16:22
文章存档

2014年(53)

我的朋友

分类: C/C++

2014-12-06 15:36:05

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.


Show Tags
Have you met this question in a real interview?

求一棵树的高度,很显然,递归,三行代码。。。


  1. int maxDepth(TreeNode *root) {
  2.         if(root==NULL)
  3.             return 0;
  4.         return max(maxDepth(root->left),maxDepth(root->right))+1;
  5.     }



阅读(724) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~