/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int minDepth(TreeNode* root)
{
if(root==NULL)
return 0;
else if(root->left&&!root->right)
return 1+minDepth(root->left);
else if(root->right&&!root->left)
return 1+minDepth(root->right);
else
return 1+min(minDepth(root->left),minDepth(root->right));
}
};
05-21
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交