```
class Solution {
public:
string getPermutation(int n, int k) {
vector<int> cnt(n+1, 1);
for(int i = 1; i <= n; i ++) cnt[i] = i * cnt[i-1];
vector<char> candidate;
string ans = "";
for(int i = 1; i <= n; i ++) candidate.push_back('0' + i);
while(n > 0) {
int idx = (k - 1) / cnt[n-1];
ans += candidate[idx];
candidate.erase(candidate.begin() + idx);
k -= idx * cnt[n-1];
n --;
}
return ans;
}
};
```