public void recoverTree(TreeNode root) {
    	ArrayList<TreeNode> nodes = new ArrayList<TreeNode>();
    	inorder(nodes, root);
    	
    	TreeNode left = null;
    	TreeNode right = null;
    	for (int i = 0; i < nodes.size() - 1; i++)
    		if (nodes.get(i).val > nodes.get(i + 1).val && left == null)
			{
    			left = nodes.get(i);
    			break;
			}

    	for (int i = nodes.size() - 1; i > 0; i--)
    		if (nodes.get(i).val < nodes.get(i - 1).val && right == null)
			{
    			right = nodes.get(i);
    			break;
			}
    	int tmp = left.val;
    	left.val = right.val;
    	right.val = tmp;
    }