C++ 2 lines


  • 1
    V

    Note the trick with unsigned int to handle -1 as the large positive number. BTW, when counting lines, I only include lines with logic; so I do not count things like method signatures and closing brackets.

    unsigned int minValue(TreeNode* r, int v) {
        return r->val != v ? r->val : r->left == nullptr ? -1 : min(minValue(r->left, v), minValue(r->right, v));
    }
    int findSecondMinimumValue(TreeNode* root) {
        return minValue(root, root->val);
    }
    

Log in to reply
 

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