Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this node's value is the smaller value among its two sub-nodes. More formally, the property&nbsp;root.val = min(root.left.val, root.right.val)&nbsp;always holds.

Given such a binary tree, you need to output the second minimum value in the set made of all the nodes' value in the whole tree.

If no such second minimum value exists, output -1 instead.

&nbsp;

&nbsp;
Example 1:

Input: root = [2,2,5,null,null,5,7]
Output: 5
Explanation: The smallest value is 2, the second smallest value is 5.


Example 2:

Input: root = [2,2,2]
Output: -1
Explanation: The smallest value is 2, but there isn't any second smallest value.


&nbsp;
Constraints:


	The number of nodes in the tree is in the range [1, 25].
	1 &lt;= Node.val &lt;= 231 - 1
	root.val == min(root.left.val, root.right.val)&nbsp;for each internal node of the tree.


# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def findSecondMinimumValue(self, root: Optional[TreeNode]) -> int:
        temp1=temp2=float(inf)
        from collections import deque
        a=deque([root])
        while a:
            node=a.popleft()
            if node.valtemp1:
                if node.val
class Solution {
    int ans = Integer.MAX_VALUE;
    boolean x = true;

    public int findSecondMinimumValue(TreeNode root) {
        go(root);
        return x ? -1 : ans;
    }

    private void go(TreeNode root) {
        if (root == null) return;
        if (root.left != null) {
            if (root.left.val == root.val) go(root.left);
            else {
                x = false;
                ans = Math.min(ans, root.left.val);
            }
        }
        if (root.right != null) {
            if (root.right.val == root.val) go(root.right);
            else {
                x = false;
                ans = Math.min(ans, root.right.val);
            }
        }
    }
}
class Solution {
public:
    int findSecondMinimumValue(TreeNode* root) {
        queue<TreeNode*>q;
        q.push(root);
        vector<int>v;
        while(!q.empty()){
            v.push_back(q.front()->val);
            if(q.front()->left){
                q.push(q.front()->left);
            }
            if(q.front()->right){
                q.push(q.front()->right);
            }
            q.pop();
        }
        sort(v.begin(),v.end());
        int ans=-1;
        for(int i=1;i<v.size();i++){
            if(v[i]!=v[0]){
                return v[i];
            }
        }
        return ans;
    }
};
var findSecondMinimumValue = function(root) {
  
    let firstMin=Math.min()
    let secondMin=Math.min()
    
    const que=[root]
    
    while(que.length){
        const node=que.shift()
        if(node.val<=firstMin){
            if(node.val<firstMin)secondMin=firstMin
            firstMin=node.val
        }else if(node.val<=secondMin){
            secondMin=node.val
        }
        if(node.left)que.push(node.left)
        if(node.right)que.push(node.right)
    }
    return secondMin===Math.min()?-1:secondMin
};
Second Minimum Node In a Binary Tree