public void recoverTree(TreeNode root) {
        if (root == null || root.left == null && root.right == null) {
            return;
        }
        ArrayList<TreeNode> result = new ArrayList<TreeNode>();
        traverse(root, result);

        /* start recover */
        int first = -1, second = -1, last = 0;
        int size = result.size();
        for (int i = 0; i < size; i++) {
            if (first == -1 && result.get(i).val > result.get(i + 1).val) {
                first = i;
                last = first;
            }
            else if (first != -1) {
                if (result.get(i).val < result.get(last).val) {
                    second = i;
                }
                else {
                    last++;
                }
            }
        }
        /* swap */
        int tmp = result.get(first).val;
        result.get(first).val = result.get(second).val;
        result.get(second).val = tmp;
    }