LeetCode *** 104. Maximum Depth of Binary Tree
2016-04-01 11:25
232 查看
题目:
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.
分析:
求二叉树最长路径,用递归没得说。
代码:
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.
分析:
求二叉树最长路径,用递归没得说。
代码:
/* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; }; */ int maxDepth(struct TreeNode* root) { if(root==NULL)return 0; else{ int leftNum=maxDepth(root->left)+1; int rightNum=maxDepth(root->right)+1; return leftNum>rightNum?leftNum:rightNum; } }
相关文章推荐
- jQuery选择器总结
- 帝国败局:一代首富,因何退隐江湖?
- Android事件分发机制完全解析,带你从源码的角度彻底理解(下)
- iOS 开发之照片框架详解
- infinitescroll 通过无限制分页(json方式完整代码)
- php require和include区别
- Android内存优化之OOM
- 如何在Linux上安装Node.js
- eclipse中修改字体大小
- CMarkUp使用简介
- 将HTML从JavaScript中抽离(源自:编写可维护的JavaScript)
- 使用HTML写一个完整的注册页面
- android系统中,点击EditText时,隐藏系统软键盘,显示光标
- iOS MVVM+RAC 从框架到实战
- 文章标题warning: could not load any Objective-C class information. This will significantly reduce the qu
- javaBean
- 二叉树的非递归遍历
- 第1周 项目(A)-10坐标转换
- Android图形graphics--饼图:HoloGraphLibrary源码修改
- java单链表基本操作(二)--指定位置增加节点