Accepted 15ms c++ solution


  • 0
    R
     int minDepth(TreeNode *root) {
            
            if(!root) return 0;
            
            // meet leaf node
            if(!root->left && !root->right){
                return 1;
            }
            // meet internal node
            else{
                if(!root->left || !root->right) return root->left?minDepth(root->left)+1:minDepth(root->right)+1;
                else return min(minDepth(root->left), minDepth(root->right))+1;
            }
      }

Log in to reply
 

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