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

不能更水

posted @ 2014-06-24 14:19  卖程序的小歪  阅读(124)  评论(0编辑  收藏  举报