111.minimum-depth-of-binary-tree

2020-05-22  本文已影响0人  Optimization
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;
    }
};
上一篇下一篇

猜你喜欢

热点阅读