1. Title
Permutation Sequence
2. Http address
https://leetcode.com/problems/permutation-sequence/
3. The question
The set [1,2,3,…,n]
contains a total of n! unique permutations.
By listing and labeling all of the permutations in order,
We get the following sequence (ie, for n = 3):"123"
"132"
"213"
"231"
"312"
"321"
Given n and k, return the kth permutation sequence.
4. My code (AC)
1 void modifyMin(char min[],int index) 2 { 3 for(int i = index; i < min.length - 1; i++) 4 { 5 min[i] = min[i+1]; 6 } 7 } 8 public String getPermutation(int n, int k) { 9 10 char str [] = new char[n];11 char min [] = new char[n];12 int base = 1;13 int layer = n-1;14 //base = (n-1)!15 min[0] = ( char ) (1 + '0');16 for(int i = 1 ; i= 2)57 {58 base /= layer;59 layer--;60 }else{61 base = 1;62 }63 }64 return new String(str);65 }