classSolution{ public String getPermutation(int n, int k){ if (n == 0) { return""; } if (n == 1) { return"1"; } int fact = 1; int end = n - 1; for (int i = 2; i <= end; i++) { fact *= i; } StringBuilder sb = new StringBuilder(); List<Integer> list = new ArrayList<>(n); for (int i = 1; i <= n; i++) { list.add(i); } k--; while (sb.length() != n) { int index = k / fact; sb.append(list.get(index)); list.remove(index); k %= fact; if (end != 0) { fact /= end; } end--; } return sb.toString(); } }