美文网首页
111.minimum-depth-of-binary-tree

111.minimum-depth-of-binary-tree

作者: Optimization | 来源:发表于2020-05-22 15:57 被阅读0次
    class Solution {
    public:
        int minDepth(TreeNode* root) {
            if(!root) return 0;
            if(!root->left && !root->right) return 1;
            
            int left_depth = root->left? minDepth(root->left):INT_MAX;
            int right_depth = root->right? minDepth(root->right) :INT_MAX;
            return min(left_depth, right_depth) + 1;
        }
    };
    

    相关文章

      网友评论

          本文标题:111.minimum-depth-of-binary-tree

          本文链接:https://www.haomeiwen.com/subject/mhoqahtx.html