/**
* 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) return 0;
int h=0x3f3f3f3f;
if(!root->left && !root->right) return 1;
if(root->left) h=minDepth(root->left);
if(root->right) h=min(h,minDepth(root->right));
return h+1;
}
};
Leetcode 111. 二叉树的最小深度
最新推荐文章于 2024-04-29 11:29:27 发布