My C++ solution


  • 0
    T
    int minDepth(TreeNode* root) {
        if(root == nullptr) 
            return 0; 
     
        auto left  = minDepth(root->left), 
             right = minDepth(root->right); 
        if(left == 0) 
            return right + 1;  
        if(right == 0) 
            return left + 1; 
        
        return std::min(left, right) + 1; 
     }

Log in to reply
 

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