My c++ solution 18ms


  • 0
    L
    class Solution {
    public:
        int minDepth(TreeNode *root) {
            if(root == NULL)
                return 0;
            int left_depth = minDepth(root->left);
            int right_depth = minDepth(root->right);
            if(left_depth == 0 || right_depth == 0)
                return right_depth + left_depth + 1;
            else
                return min(left_depth, right_depth) + 1;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.