public class Solution {
public String getPermutation(int n, int k) {
StringBuilder result = new StringBuilder();
List<Integer> list = new ArrayList<Integer>();
int factorial = 1;
for (int i = 1; i <= n; i++) {
list.add(i);
factorial *= i;
}
k--;
for (int i = n; i > 0; i--) {
factorial /= i;
int index = k / factorial;
k = k % factorial;
result.append(list.get(index));
list.remove(index);
}
return result.toString();
}
}