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的更多相关文章

  1. 【LEETCODE OJ】Binary Tree Postorder Traversal

    Problem Link: http://oj.leetcode.com/problems/binary-tree-postorder-traversal/ The post-order-traver ...

  2. 【一天一道LeetCode】#107. Binary Tree Level Order Traversal II

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 来源: htt ...

  3. 【一天一道LeetCode】#103. Binary Tree Zigzag Level Order Traversal

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 来源: htt ...

  4. C++版 - 剑指offer 面试题39:判断平衡二叉树(LeetCode 110. Balanced Binary Tree) 题解

    剑指offer 面试题39:判断平衡二叉树 提交网址:  http://www.nowcoder.com/practice/8b3b95850edb4115918ecebdf1b4d222?tpId= ...

  5. (二叉树 递归) 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 ...

  6. (二叉树 递归) 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 ...

  7. [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 ...

  8. LeetCode——Diameter of Binary Tree

    LeetCode--Diameter of Binary Tree Question Given a binary tree, you need to compute the length of th ...

  9. [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 ...

随机推荐

  1. apt-get doesn't work

    apt-get upgrade Reading package lists... DoneBuilding dependency tree       Reading state informatio ...

  2. PostgreSQL的checkpoint能否并行

    对于此问题,在社区进行了提问,并得到了一些大牛的解答: http://postgresql.1045698.n5.nabble.com/Can-checkpoint-creation-be-paral ...

  3. day5 二值化

    1.otsu二值化 # coding=utf-8 import cv2 import numpy as np from matplotlib import pyplot as plt #1.读入图像 ...

  4. 【Loj10222】佳佳的Fibonacci

    题面 题解 可以发现\(T(n)\)无法用递推式表示. 于是我们做如下变形: \[ T(n) = \sum _ {i = 1} ^ n i \times f_i \\ S(n) = \sum _ {i ...

  5. linux挂在samba服务器到本地(用于备份文件到nas或者windows的文件服务器)

    1.安装工具 首先在linux上安装samba访问工具 sudo apt-get install smbclient sudo apt-get install cifs-utils 2.查看服务器目录 ...

  6. Phaser游戏框架与HTML Dom元素之间的通信交互

    本想按照PHASER的HTML Dom元素官方实例:http://labs.phaser.io/index.html?dir=game%20objects/dom%20element/&q=  ...

  7. Unity —— 通过鼠标点击控制物体移动

    //ClickMove - - 通过鼠标点击控制物体移动 using System.Collections; using System.Collections.Generic; using Unity ...

  8. python-将爬取到的m3u8合并为mp4

    当你看到这个博客的时候恭喜你,你以后不用开vip就可以观看和下载vip视频了 最简单的观看vip视频步骤:进入全民解析网将vip视频地址进行解析 以下代码是通过python将vip视频进行下载为mp4 ...

  9. NO.02---聊聊Vue提升

    如果本篇有看不明白的地方,请翻阅上一篇文章 上一篇我们讲了如何通过一些简单的动作来改变 store.js 中的数据对象,在实际工作中,这是完全无法满足工作需求的,所以这篇我们来说说如何做一些简单的流程 ...

  10. dotnet服务器端框架从精通到弃坑

    当你们看到这篇经验分享的时候,我已经把服务器端主要力量转到JAVA了. 纯当留念. 另外里面实现oauth2.0的部分就不写了,因为特殊性太强,完全根据自家需求结合它的理念改写的. 为什么我会选择sp ...