Class Solution

java.lang.Object
g0001_0100.s0060_permutation_sequence.Solution

public class Solution extends Object
60 - Permutation Sequence.<p>Hard</p> <p>The set <code>[1, 2, 3, ..., n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><code>&quot;213&quot;</code></li> <li><code>&quot;231&quot;</code></li> <li><code>&quot;312&quot;</code></li> <li><code>&quot;321&quot;</code></li> </ol> <p>Given <code>n</code> and <code>k</code>, return the <code>kth</code> permutation sequence.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 3, k = 3</p> <p><strong>Output:</strong> &ldquo;213&rdquo;</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 4, k = 9</p> <p><strong>Output:</strong> &ldquo;2314&rdquo;</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> n = 3, k = 1</p> <p><strong>Output:</strong> &ldquo;123&rdquo;</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 9</code></li> <li><code>1 <= k <= n!</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • getPermutation

      public String getPermutation(int n, int k)