/**
 * struct TreeNode {
 *	int val;
 *	struct TreeNode *left;
 *	struct TreeNode *right;
 * };
 */

class Solution {
public:
    /**
     * 
     * @param root TreeNode类 the root
     * @return int整型vector
     */
    void dfs(TreeNode* root, vector<int>& vec) {
        if(!root)
            return;
        dfs(root->left, vec);
        vec.push_back(root->val);
        dfs(root->right, vec);
    }
    vector<int> findError(TreeNode* root) {
        // write code here
        vector<int> res, tmp;
        dfs(root, res);
        // res作为遍历树的顺序列表
        if(res.size() < 2)
            return tmp;
        int pre = res[0];
        for(int i = 0; i < res.size() - 1; i++) {
            if(res[i] > res[i+1]) {
                tmp.push_back(res[i]);
                int j = i + 1;
                while(j < res.size() && res[j] < res[i])
                    j++;
                tmp.push_back(res[j-1]);
                break;
            }
        }
        swap(tmp[0], tmp[1]);
        return tmp;
    }
};