104. Maximum Depth of Binary Tree

104

[思路:]

  • 寻找树的最大深度,深度优先;
    int maxDepth(TreeNode* root) {
        if (!root) return 0;
        return max(maxDepth(root->left), maxDepth(root->right)) + 1;
    }

你可能感兴趣的:(104. Maximum Depth of Binary Tree)