2 lines c++ solution


  • 0
    Z
    class Solution {
    public:
        int minDepth(TreeNode* root) {
            if(!root) return 0;
            return root->left == NULL || root->right == NULL ? 1+max(minDepth(root->left), minDepth(root->right)) : 1+min(minDepth(root->left), minDepth(root->right));
        }
    };
    

Log in to reply
 

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