publicclassPermutationSequence{ public String getPermutation(int n, int k){ int t = 1; List<Integer> numbers = new ArrayList<Integer>(n); for (int i = 1; i <= n; i++) { t = t * i; numbers.add(i); } t /= n; k--; StringBuilder sb = new StringBuilder(); for (int i = n - 1; i >= 1; i--) { int p = k / t; int np = numbers.get(p); sb.append(np); numbers.remove(p); k %= t; t /= i; } sb.append(numbers.get(0)); return sb.toString(); } }