LeetCode Maximum Depth of Binary Tree

时间:2014-06-25 18:40:33   收藏:0   阅读:259
/**
 * 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 0;
        }
        int dl = maxDepth(root->left);
        int dr = maxDepth(root->right);
        return max(dl, dr) + 1;
    }
};

不能更水

LeetCode Maximum Depth of Binary Tree,布布扣,bubuko.com

原文:http://www.cnblogs.com/lailailai/p/3805990.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!