/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
void find(TreeNode*root, int &min,int &min1,bool &change)
{
if(root->val<min)
{
min = root->val;
}
if(root->val>min&&root->val<=min1)
{
change = true;
min1 = root->val;
}
if(root->left==NULL&&root->right==NULL)
{
return;
}
if(root->left!=NULL)
find(root->left,min,min1,change);
if(root->right!=NULL)
find(root->right,min,min1,change);
}
int findSecondMinimumValue(TreeNode* root) {
int min=INT_MAX,min2=INT_MAX;
bool change=false;
find(root,min,min2,change);
if(min==min2)return -1;
if(min2==INT_MAX&&!change)return -1;
else return min2;
}
};