int minDepth(TreeNode *root) {

if (root == NULL) // leaf boundary

return 0;

if (root->right != NULL && root->left != NULL)

return min(minDepth(root->right) + 1, minDepth(root->left) + 1);

else if (root->right != NULL && root->left == NULL)

return minDepth(root->right) + 1;

else

return minDepth(root->left) + 1;

}