Simple C++ 6ms Solution


  • 0
    M
    int minDepth(TreeNode* root) {
            if(!root) return 0;
            return getMinumumDepth(root);
        }
        
        int getMinumumDepth(TreeNode* root){
            if(root){
                if(!root->left && !root->right) return 1;
            
            
                int leftChildMin = getMinumumDepth(root->left);
                int rightChildMin = getMinumumDepth(root->right);
            
                return min(leftChildMin, rightChildMin) + 1;
            }
            return INT_MAX;
        }
    

Log in to reply
 

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