Title: #60 - Permutation Sequence - LeetCode JavaScript Solutions
Open Graph Title: #60 - Permutation Sequence - LeetCode JavaScript Solutions
X Title: #60 - Permutation Sequence - LeetCode JavaScript Solutions
Description: The set [1, 2, 3, ..., n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, we get the f...
Open Graph Description: The set [1, 2, 3, ..., n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, we get the f...
X Description: The set [1, 2, 3, ..., n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, we get the f...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/permutation-sequence
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/permutation-sequence","name":"#60 - Permutation Sequence - LeetCode JavaScript Solutions","description":"The set [1, 2, 3, ..., n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, we get the f...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {number} n\n * @param {number} k\n * @return {string}\n */\nvar getPermutation = function(n, k) {\n const factorial = [1];\n for (let i = 1; i < n; i++) {\n factorial[i] = factorial[i-1] * i;\n }\n\n const values = new Array(n).fill(0).map((_, i) => i + 1);\n let result = '';\n k--;\n\n for (let i = n - 1; i >= 0; i--) {\n const index = Math.floor(k / factorial[i]);\n k = k % factorial[i];\n result += values[index];\n values.splice(index, 1);\n }\n\n return result;\n};","keywords":"LeetCode 60, #60 - Permutation Sequence, Hard, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/permutation-sequence |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/permutation-sequence/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0060-permutation-sequence.js |
| Math | https://leetcodejavascript.com/tags/math |
| Recursion | https://leetcodejavascript.com/tags/recursion |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow