//方法-: class Solution { public: int run(TreeNode *root) { if(!root) return 0; queue<pair<TreeNode*,int>> que; que.push(make_pair(root,1)); pair<TreeNode*,int> p; int ans=0; while(!que.empty()){ p=que.front(); if(!(p.first->left)&&!(p.first->right)){ return p.second; } que.pop(); if(p.first->left) {que.push(make_pair(p.first->left,p.second+1));} if(p.first->right){que.push(make_pair(p.first->right,p.second+1));} } } }; //方法二: class Solution { public: int run(TreeNode *root) { if(!root) return 0; queue<TreeNode*> que; que.push(root); TreeNode* p; int level=0; while(!que.empty()){ level++; int size=que.size(); while(size--){ p=que.front(); que.pop(); if(!p->left&&!p->right) return level; if(p->left) que.push(p->left); if(p->right) que.push(p->right); } } } }; //方法三: class Solution { public: int ans=0x3fffffff,n=0; void order(TreeNode *root){ if(!root) return; ++n; if(!root->left&&!root->right){ ans=min(ans,n); } order(root->left); order(root->right); --n; } int minDepth(TreeNode* root) { if(!root) return 0; order(root); return ans; } };