We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0eb9312 commit fffc6d0Copy full SHA for fffc6d0
solution/0060.Permutation Sequence/Solution.java
@@ -0,0 +1,20 @@
1
+class Solution {
2
+ public String getPermutation(int n, int k) {
3
+ StringBuilder s = new StringBuilder();
4
+ int[] fact = new int[n];
5
+ fact[0] = 1;
6
+ for (int i = 1; i < n; i++)
7
+ fact[i] = fact[i - 1] * i;
8
+ List<Integer> list = new ArrayList<>();
9
+ for (int i = 1; i <= n; i++)
10
+ list.add(i);
11
+ k--;
12
+ for (int i = n; i >= 1; i--) {
13
+ int j=k/fact[i-1];
14
+ k=k%fact[i-1];
15
+ s.append(list.get(j));
16
+ list.remove(j);
17
+ }
18
+ return s.toString();
19
20
+}
0 commit comments