关闭

104. Maximum Depth of Binary Tree

标签: 104. Maximum Depth oleetcodeC++
170人阅读 评论(0) 收藏 举报
分类:
/**
 * Definition for a binary tree node.
 * 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 0;
        int leftD=maxDepth(root->left);
        int rightD=maxDepth(root->right);
        return leftD>=rightD?leftD+1:rightD+1;
    }
};

0
0
查看评论

leetcode 104 Maximum Depth of Binary Tree二叉树求深度

Maximum Depth of Binary Tree Total Accepted: 63668 Total Submissions: 141121 My Submissions Question Solution Given a binary tree, find its maxi...
  • wangyaninglm
  • wangyaninglm
  • 2015-05-13 22:16
  • 3785

【LeetCode-面试算法经典-Java实现】【104-Maximum Depth of Binary Tree(二叉树的最大深度)】

【104-Maximum Depth of Binary Tree(二叉树的最大深度)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题  Given a binary tree, find its maximum depth.   The maximum depth is...
  • DERRANTCM
  • DERRANTCM
  • 2015-08-08 06:43
  • 2949

LeetCode104——Maximum Depth 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 farthes...
  • booirror
  • booirror
  • 2015-02-05 15:29
  • 1528

104. Maximum Depth of Binary Tree [easy] (Python)

题目链接https://leetcode.com/problems/maximum-depth-of-binary-tree/题目原文 Given a binary tree, find its maximum depth. The maximum depth is the numbe...
  • coder_orz
  • coder_orz
  • 2016-05-07 13:21
  • 1404

【LeetCode】【Python题解】Single Number & Maximum Depth of Binary Tree

今天做了三道LeetCode上的简单题目,每道题都是用c++和Python两种语言写的,因为c++版的代码网上比较多,所以就只分享一下Python的代码吧,刚学完Python的基本语法,做做LeetCode的题目还是不错的,对以后找工作面试也有帮助! 刚开始就从AC率最高的入手吧! ...
  • u011613729
  • u011613729
  • 2014-07-20 13:18
  • 3633

Maximum Depth of Binary Tree -- LeetCode

原题链接: http://oj.leetcode.com/problems/merge-two-sorted-lists/  这道题目比较简单,经典的链表基本操作。维护两个指针对应两个链表,因为一般会以一条链表为基准,比如说l1, 那么如果l1当期那的元素比较小,那么直接移动l1...
  • linhuanmars
  • linhuanmars
  • 2014-02-22 03:34
  • 12703

【LeetCode】104. Maximum Depth of Binary Tree(DFS|BFS)

原题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 ...
  • jiange_zh
  • jiange_zh
  • 2016-01-07 10:05
  • 794

LeetCode 104 -Maximum Depth of Binary Tree ( JAVA )

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 farthes...
  • UckyK
  • UckyK
  • 2016-04-05 18:27
  • 604

Given a binary tree, find its maximum depth.

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 farthes...
  • u010850285
  • u010850285
  • 2014-05-23 14:21
  • 732

maximum-depth-of-binary-tree(二叉树的最大深度)

maximum-depth-of-binary-tree(二叉树的最大深度)题目:maximum-depth-of-binary-tree Given a binary tree, find its maximum depth. The maximum depth is the numbe...
  • five0918
  • five0918
  • 2016-09-07 20:55
  • 436
    个人资料
    • 访问:15452次
    • 积分:573
    • 等级:
    • 排名:千里之外
    • 原创:42篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条