C++求排列有三种方法:

  1. 利用库函数next_permutation
  2. 基于交换
  3. 基于回溯

下面用库函数next_permutation求:

//
// Created by jt on 2020/9/26.
//
#include <vector>
#include <string>
using namespace std;

class Solution {
public:
    /**
     *
     * @param n int整型
     * @param k int整型
     * @return string字符串
     */
    string getPermutation(int n, int k) {
        // write code here
        vector<char> vec;
        for (int i = 1; i <= n; ++i) vec.push_back(i+'0');
        while (--k > 0 && next_permutation(vec.begin(), vec.end())) {}
        return string(vec.begin(), vec.end());
    }
};