你的想法是对的。但是实现起来还是优点麻烦。 如果一个数组的长度是n,那末,一共有n!种排列. 每种都可以写成基数{n, n-1, .. ., 2, 1, 0}的格式。比如,第一个到第三个是{0,0...,1,0},{0,0...1,0,0},{0,0.. .2,1,0}. 这个序列的含义是左边有多少个数比当前的数大。 比如,给定一个排列 {3,2,1,4}, 那末对应的序列是{2,1,0,0}. 根据这种方法,对于一个随机数,可以在o(n)内产生对应的排列。 代码: 完整的代码在: http://code.google.com/p/sureinterview/source/browse/src/lib/combination/PermutationImpl.java 看看有问题没? @Override public T[] get(Long index) { // adjust to 1-based. index++; // parse the index to {n-1, n-2, ... 3, 2, 1, 0}-based number. // For example, 10 = {1, 1, 1, 1, 0}. The meaning of each digits is the // number of digits on the left greater than current digit. For example, // in object list {a, b, d, c, e}, The corresponding index = {0, 0, 1, // 0, 0}. Because c has d on the left. Integer[] permArr = new Integer[n]; for (int i = n - 1; i >= 0; i--) { permArr[i] = (int) ((index % (n - i))); index /= n - i; } // keep objList2 as a reference. T[] objList2 = Arrays.copyOf(objList, n); for (int objIdx = 0; objIdx < n; objIdx++) { int pos = 0; // get current object obj and find its current position in the // object list. T obj = objList2[objIdx]; for (int i = 0; i < n; i++) { if (obj.equals(objList[i])) { pos = i; break; } } // the number of objects in reversed order (objects on the left and // greater than current object.) int revOrd = permArr[objIdx]; for (int i = 0; i < n; i++) { // no object in reversed order. done. if (revOrd <= 0) break; // pass if the objects in list are smaller than current obj if (obj.compareTo(objList[i]) >= 0) continue; // move to larger objects to the left to fulfill "revOrd" number // of objects in reversed order. if (i > pos) { objList[pos] = objList[i]; pos = i; } revOrd--; if (revOrd <= 0) { // put obj back for the last one objList[pos] = obj; break; } } } return objList; }