Leetcode-104. Maximum Depth of Binary Tree

    xiaoxiao2021-03-25  172

    题目

    Given a binary tree, find its maximum depth.

    The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 求二叉树的最大深度

    代码

    class Solution { public: int maxDepth(TreeNode* root) { if(!root) return 0; int left = maxDepth(root->left); int right = maxDepth(root->right); return 1 + (left > right ? left : right); } };

    相关问题:Leetcode-111. Minimum Depth of Binary Tree

    转载请注明原文地址: https://ju.6miu.com/read-859.html

    最新回复(0)