[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 ...
随机推荐
- 20145234黄斐《网络对抗技术》实验五,MSF基础应用
MSF的六种模块 渗透攻击模块(Exploit Modules)渗透攻击是指由攻击者或渗透测试者利用一个系统.应用或服务中的==安全漏洞==,所进行的攻击行为. 辅助模块(Auxiliary Modu ...
- PostgreSQL的pg_stats学习
磨砺技术珠矶,践行数据之道,追求卓越价值 回到上一级页面: PostgreSQL统计信息索引页 回到顶级页面:PostgreSQL索引页 对于pg_stas,说明文档在这里: http://w ...
- 获取文件mimes
<?php /* * Copyright 2010-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licen ...
- 四、Django设置相关
1.全局设置 setttings文件 import os import sys # Build paths inside the project like this: os.path.join(BAS ...
- Linux 内核3.10.5 专场
今天本人十分靠谱地下载了linux 内核的3.10.5版本,这个版本是最新的稳定版. 听路飞大虾(哪个路飞?就是那个戴草帽的橡胶小伙,航海很多时候都很空闲的,于是最近他也开始研读linux 内核了.) ...
- Git操作指令
1.创建版本库 git init 2.把工作区修改过的文件添加到版本库暂存区,点号表示当前目录下所有文件; git add .#查看仓库状态git status 3.把版本库暂存区的文件提交到当前分支 ...
- eclipse查看源代码问题
最近分析源代码时,eclipse总是出错,显示org.eclipse.core.runtime.CoreException,解决方法:在builderpath点击 add external jars, ...
- throttle(节流)和debounce(防抖)
防抖和节流都是用来控制频繁调用的问题,但是这两种的应用场景是有区别的. throttle(节流) 有一个调用周期,在一个很长的时间里分为多段,每一段执行一次.例如onscroll,resize,500 ...
- java之接口开发-初级篇-socket通信
socket通信实现util包类实现 public class SocketThread extends Thread { public void run() { while (true) { // ...
- VMware VSAN 入门与配置(一)
----VMware VSAN beta版已经出来一段时间了,今天终于正式发布(同时VMware View 5.3.1也正是发布,在5.3的基础上增加了VSAN的支持) VSAN 产品主页 http: ...