码迷,mamicode.com
首页 > 其他好文 > 详细

97.二叉树的最大深度

时间:2018-09-13 22:46:48      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:分享图片   href   html   深度   efi   node   maximum   leetcode   this   

转自[LeetCode] Maximum Depth of Binary Tree 二叉树的最大深度
技术分享图片

/**
 * Definition of TreeNode:
 * class TreeNode {
 * public:
 *     int val;
 *     TreeNode *left, *right;
 *     TreeNode(int val) {
 *         this->val = val;
 *         this->left = this->right = NULL;
 *     }
 * }
 */

class Solution {
public:
    /**
     * @param root: The root of binary tree.
     * @return: An integer
     */
    int maxDepth(TreeNode * root) {
        if (!root) return 0;
        return 1 + max(maxDepth(root->left), maxDepth(root->right));
    }
};

97.二叉树的最大深度

标签:分享图片   href   html   深度   efi   node   maximum   leetcode   this   

原文地址:https://www.cnblogs.com/narjaja/p/9643254.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!