[LeetCode] MaximumDepth of Binary Tree
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.
/**
* Definition for binary tree
* 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 ; int left_depth = maxDepth(root->left);
int right_depth = maxDepth(root->right); return left_depth > right_depth ? left_depth + : right_depth + ;
}
};
[LeetCode] MaximumDepth of Binary Tree的更多相关文章
- 【LEETCODE OJ】Binary Tree Postorder Traversal
Problem Link: http://oj.leetcode.com/problems/binary-tree-postorder-traversal/ The post-order-traver ...
- 【一天一道LeetCode】#107. Binary Tree Level Order Traversal II
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 来源: htt ...
- 【一天一道LeetCode】#103. Binary Tree Zigzag Level Order Traversal
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 来源: htt ...
- C++版 - 剑指offer 面试题39:判断平衡二叉树(LeetCode 110. Balanced Binary Tree) 题解
剑指offer 面试题39:判断平衡二叉树 提交网址: http://www.nowcoder.com/practice/8b3b95850edb4115918ecebdf1b4d222?tpId= ...
- (二叉树 递归) leetcode 105. Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...
- (二叉树 递归) leetcode 106. Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...
- [LeetCode] 106. Construct Binary Tree from Postorder and Inorder Traversal_Medium tag: Tree Traversal
Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...
- LeetCode——Diameter of Binary Tree
LeetCode--Diameter of Binary Tree Question Given a binary tree, you need to compute the length of th ...
- [LeetCode] 106. Construct Binary Tree from Inorder and Postorder Traversal 由中序和后序遍历建立二叉树
Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...
随机推荐
- Java使用POI导出excel(上)——基本操作
相关的介绍参考自:http://zc985552943.iteye.com/blog/1491546 一.概述 1.概念 受上文博文博主的启发,有必要先对excel的各个概念先做了解! //上述基本都 ...
- kali更新源相关 -- 没有release文件、签名无效、404
kali更新源相关 -- 没有release文件.签名无效.404 这个随笔主要是处理Mac下使用VMare虚拟机安装Kali时候我遇到的一些关于更新源的问题 (因为本人为了这个问题折腾了四五个小时, ...
- Spring MVC接受参数的注解
一.Request请求发出后,Headler Method是如何接收处理数据的? Headler Method绑定常用的参数注解,根据处理request的不同部分分为四类: A.处理 Request ...
- day 6 汽车4S店铺
1.版本1:大框架 class CarStore(object): '''定义一个汽车店铺类''' pass class Car(object): '''定义一个汽车类''' pass car_sto ...
- 【python笔记】python中的list、tuple、set、dict用法简析
list list是一种有序的集合(或称作列表),可以很方便地添加和删除其中的元素. >>> classmates = ['Michael', 'Bob', 'Tracy'] 可通过 ...
- 查询表的大小(mysql)
--所有表的大小 select concat(round(sum(DATA_LENGTH/1024/1024),2),'M') from information_schema.tables where ...
- Redash二次开发-开发环境搭建
环境:win7+pycharm 2018.2 +redash 1.安装pycharm并如何正常使用,找度娘. 2.配置pycharm vcs,设置github用户,从github新建redash项目 ...
- 《图解 HTTP 》阅读 —— 第四章
第4章 返回结果的HTTP状态码 1XX 接收的请求正在处理 2XX 请求被处理 200 请求成功 204 请求成功,但是没有返回数据 206 客户端进行了范围请求 3XX 重定向 301 永久性重定 ...
- 常用JDBC数据库驱动包和类名
MySQL数据库: 1)驱动包:https://mvnrepository.com/artifact/mysql/mysql-connector-java(下载路径) 2)驱动类名:com.mysql ...
- [linux] reboot和shutdown-r的区别
google看看: 先搜英文的资料 http://askubuntu.com/questions/441969/what-is-the-difference-between-reboot-and-sh ...