public static List<Integer> nextPermuation(List<Integer> nums) {
		// write your code
		List<Integer>A=nums;
		int n=A.size(),i=n-1;
		while (i>0&&A.get(i-1)>=A.get(i))
		    --i;
		if (--i<0) {
		    Collections.reverse(A);
		    return A;
		}
		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 A;
    }