class Solution {
public:
    vector<int> V;

    void postTree(TreeNode* node)
    {
        if (node != NULL)
        {
            V.push_back(node->val);
            if (node->left != NULL)
            {
                postTree(node->left);
            }
            if (node->right != NULL)
            {
                postTree(node->right);
            }
        }
    }

    int findSecondMinimumValue(TreeNode* root) {
        postTree(root);
        int result = -1;
        if (V.size() < 2)
        {
            return -1;
        }        
        sort(V.begin(), V.end());
        for (auto v : V)
        {
            cout << v << " ";
        }
        cout << endl;
        for (int i = 1; i < V.size(); i++)
        {
            if (V[i - 1] == V[i])
            {
                continue;
            }
            else
            {
                result = V[i];
                break;
            }
        }
        return result;
    }
};

 

posted on 2018-10-01 09:48  Sempron2800+  阅读(94)  评论(0编辑  收藏  举报