2022-03-27 20:56:26 +08:00
|
|
|
<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>"123"</code></li>
|
|
|
|
<li><code>"132"</code></li>
|
|
|
|
<li><code>"213"</code></li>
|
|
|
|
<li><code>"231"</code></li>
|
|
|
|
<li><code>"312"</code></li>
|
|
|
|
<li><code>"321"</code></li>
|
|
|
|
</ol>
|
|
|
|
|
|
|
|
<p>Given <code>n</code> and <code>k</code>, return the <code>k<sup>th</sup></code> permutation sequence.</p>
|
|
|
|
|
|
|
|
<p> </p>
|
2023-12-09 18:42:21 +08:00
|
|
|
<p><strong class="example">Example 1:</strong></p>
|
2022-03-27 20:56:26 +08:00
|
|
|
<pre><strong>Input:</strong> n = 3, k = 3
|
|
|
|
<strong>Output:</strong> "213"
|
2023-12-09 18:42:21 +08:00
|
|
|
</pre><p><strong class="example">Example 2:</strong></p>
|
2022-03-27 20:56:26 +08:00
|
|
|
<pre><strong>Input:</strong> n = 4, k = 9
|
|
|
|
<strong>Output:</strong> "2314"
|
2023-12-09 18:42:21 +08:00
|
|
|
</pre><p><strong class="example">Example 3:</strong></p>
|
2022-03-27 20:56:26 +08:00
|
|
|
<pre><strong>Input:</strong> n = 3, k = 1
|
|
|
|
<strong>Output:</strong> "123"
|
|
|
|
</pre>
|
|
|
|
<p> </p>
|
|
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li><code>1 <= n <= 9</code></li>
|
|
|
|
<li><code>1 <= k <= n!</code></li>
|
|
|
|
</ul>
|