LeetCode Maximum Depth of Binary Tree

/**
 * 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;
    }
};

不能更水

原文地址:https://www.cnblogs.com/lailailai/p/3805990.html