Simplest C++ Recursive One-Liner


  • 0
    M
    class Solution {
    public:
        int minDepth(TreeNode* root) {
            return !root ? 0 : root->left && root->right ? min(minDepth(root->left), minDepth(root->right)) + 1 : root->left ? minDepth(root->left) + 1 : root->right ? minDepth(root->right) + 1 : 1;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.