[leetcode-111-minimum depth of binary tree]
1 /*Given a binary tree, find its minimum depth.The minimum depth is the number of nodes 2 along the shortest path from the root node down to the nearest leaf node.*/ 3 int minDepth(TreeNode *root) 4 { 5 if(root == NULL) return 0; 6 if (root->left==NULL) return 1 + minDepth(root->right); 7 if (root->right == NULL) return 1 + minDepth(root->left); 8 return 1 + min(minDepth(root->left), minDepth(root->right)); 9 }