C++ Recursive Solution Runtime ~3ms

  • 0
     int findSecondMinimumValue(TreeNode* root) {
            int res  = findMin(root,root->val);         
            return res == INT_MAX?-1:res;
        int findMin(TreeNode* root, int first_min){
                if(root->val!=first_min)     return root->val;         
                int left = findMin(root->left,first_min);
                int right = findMin(root->right,first_min);
                return min(right,left);
            return INT_MAX;

Log in to reply

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