104. Maximum Depth of Binary Tree

 int maxDepth(TreeNode* root) {

        if(!root) return 0;
        int maxLeft = maxDepth(root->left);
        int maxRight = maxDepth(root->right);
        return max(maxLeft, maxRight)+1;
    }

Comments

Popular posts from this blog

2161. Partition Array According to Given Pivot

2000. Reverse Prefix of Word

1769. Minimum Number of Operations to Move All Balls to Each Box