[LeetCode] 60. Permutation Sequencejava

    xiaoxiao2021-03-25  131

    /**60. Permutation Sequence * @param n * @param k * @return */ public String getPermutation(int n, int k) { k--;//to transfer it as begin from 0 rather than 1 List<Integer> numList = new ArrayList<Integer>(); for(int i = 1; i<= n; i++) numList.add(i); int factorial = 1; for(int i = 2; i < n; i++) factorial *= i; StringBuilder res = new StringBuilder(); int times = n-1; while(times>=0){ int indexInList = k/factorial; res.append(numList.get(indexInList)); numList.remove(indexInList); k = k
    转载请注明原文地址: https://ju.6miu.com/read-5099.html

    最新回复(0)