1class Solution {2public:3vector<int> v;4int i = 0;5void inorder(TreeNode *root) {6if (!root) return;7inorder(root->left);8v.push_back(root->val);9inorder(root->right);10}11void check(TreeNode *root) {12if (!root) return;13check(root->left);14if (v[i] != root->val) swap(v[i], root->val);15i++;16check(root->right);17}18void recoverTree(TreeNode *root) {19inorder(root);20sort(v.begin(), v.end());21check(root);22}23};