1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8 * }; 9 */ 10 class Solution { 11 public: 12 13 int min=10000; 14 void meng(TreeNode*root,int dep) 15 { 16 if((root->left==NULL)&&(root->right==NULL)) 17 { 18 if(dep<min) 19 min=dep; 20 return; 21 } 22 if(root->left) 23 meng(root->left,dep+1); 24 if(root->right) 25 meng(root->right,dep+1); 26 } 27 int minDepth(TreeNode *root) { 28 // Start typing your C/C++ solution below 29 // DO NOT write int main() function 30 min=10000; 31 if(root==NULL) 32 return 0; 33 meng(root,1); 34 return min; 35 } 36 };