12ms one line C++ solution


  • -5
    P
    class Solution {
    public:
    int minDepth(TreeNode* root) {
        return root? (root->left && root ->right)? min(minDepth(root->left) + 1, minDepth(root->right)+1) : max (minDepth(root->left) + 1, minDepth(root->right)+1) : 0;
    }
    };

Log in to reply
 

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