public static ArrayList<Integer> previousPermuation(ArrayList<Integer> nums) {
		// write your code
		List<Integer>A=nums;
		int n=A.size();
		int i=n-1;
		while (i>0&&A.get(i-1)<=A.get(i))
		    --i;
		if (--i<0) {
		    Collections.reverse(A);
		    return nums;
		}
		int j=n-1;
		while (j>i&&A.get(j)>=A.get(i))
		    --j;
		Collections.swap(A,i,j);
		Collections.reverse(A.subList(i+1,n));
		return nums;
    }