2023年1月14日 星期六

104. Maximum Depth of Binary Tree

程式碼

class Solution {
public:
    int getDepth(TreeNode* p)
    {
        if(p == nullptr)
            return 0;
        return max(getDepth(p->left), getDepth(p->right)) + 1;
    }
    int maxDepth(TreeNode* root) {
        return getDepth(root);
    }
};

沒有留言:

張貼留言