1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-03-14 08:12:25 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

174 lines
21 KiB
JSON
Raw Normal View History

2022-03-27 20:56:26 +08:00
{
"data": {
"question": {
"questionId": "60",
"questionFrontendId": "60",
"categoryTitle": "Algorithms",
"boundTopicId": 1307,
"title": "Permutation Sequence",
"titleSlug": "permutation-sequence",
2023-12-09 18:42:21 +08:00
"content": "<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p>\n\n<p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p>\n\n<ol>\n\t<li><code>&quot;123&quot;</code></li>\n\t<li><code>&quot;132&quot;</code></li>\n\t<li><code>&quot;213&quot;</code></li>\n\t<li><code>&quot;231&quot;</code></li>\n\t<li><code>&quot;312&quot;</code></li>\n\t<li><code>&quot;321&quot;</code></li>\n</ol>\n\n<p>Given <code>n</code> and <code>k</code>, return the <code>k<sup>th</sup></code> permutation sequence.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<pre><strong>Input:</strong> n = 3, k = 3\n<strong>Output:</strong> \"213\"\n</pre><p><strong class=\"example\">Example 2:</strong></p>\n<pre><strong>Input:</strong> n = 4, k = 9\n<strong>Output:</strong> \"2314\"\n</pre><p><strong class=\"example\">Example 3:</strong></p>\n<pre><strong>Input:</strong> n = 3, k = 1\n<strong>Output:</strong> \"123\"\n</pre>\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= n &lt;= 9</code></li>\n\t<li><code>1 &lt;= k &lt;= n!</code></li>\n</ul>\n",
2022-03-27 20:56:26 +08:00
"translatedTitle": "排列序列",
"translatedContent": "<p>给出集合 <code>[1,2,3,...,n]</code>,其所有元素共有 <code>n!</code> 种排列。</p>\n\n<p>按大小顺序列出所有排列情况,并一一标记,当 <code>n = 3</code> 时, 所有排列如下:</p>\n\n<ol>\n\t<li><code>\"123\"</code></li>\n\t<li><code>\"132\"</code></li>\n\t<li><code>\"213\"</code></li>\n\t<li><code>\"231\"</code></li>\n\t<li><code>\"312\"</code></li>\n\t<li><code>\"321\"</code></li>\n</ol>\n\n<p>给定 <code>n</code> 和 <code>k</code>,返回第 <code>k</code> 个排列。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>n = 3, k = 3\n<strong>输出:</strong>\"213\"\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>n = 4, k = 9\n<strong>输出:</strong>\"2314\"\n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre>\n<strong>输入:</strong>n = 3, k = 1\n<strong>输出:</strong>\"123\"\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= n <= 9</code></li>\n\t<li><code>1 <= k <= n!</code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Hard",
2023-12-09 18:42:21 +08:00
"likes": 824,
2022-03-27 20:56:26 +08:00
"dislikes": 0,
"isLiked": null,
2023-12-09 18:42:21 +08:00
"similarQuestions": "[{\"title\": \"Next Permutation\", \"titleSlug\": \"next-permutation\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u4e0b\\u4e00\\u4e2a\\u6392\\u5217\", \"isPaidOnly\": false}, {\"title\": \"Permutations\", \"titleSlug\": \"permutations\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u5168\\u6392\\u5217\", \"isPaidOnly\": false}]",
2022-03-27 20:56:26 +08:00
"contributors": [],
2023-12-09 18:42:21 +08:00
"langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python\": true, \"python3\": true, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}",
2022-03-27 20:56:26 +08:00
"topicTags": [
{
"name": "Recursion",
"slug": "recursion",
"translatedName": "递归",
"__typename": "TopicTagNode"
},
{
"name": "Math",
"slug": "math",
"translatedName": "数学",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
"lang": "C++",
"langSlug": "cpp",
"code": "class Solution {\npublic:\n string getPermutation(int n, int k) {\n\n }\n};",
"__typename": "CodeSnippetNode"
},
{
"lang": "Java",
"langSlug": "java",
"code": "class Solution {\n public String getPermutation(int n, int k) {\n\n }\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Python",
"langSlug": "python",
"code": "class Solution(object):\n def getPermutation(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: str\n \"\"\"",
"__typename": "CodeSnippetNode"
},
{
"lang": "Python3",
"langSlug": "python3",
"code": "class Solution:\n def getPermutation(self, n: int, k: int) -> str:",
"__typename": "CodeSnippetNode"
},
{
"lang": "C",
"langSlug": "c",
2023-12-09 18:42:21 +08:00
"code": "char* getPermutation(int n, int k) {\n \n}",
2022-03-27 20:56:26 +08:00
"__typename": "CodeSnippetNode"
},
{
"lang": "C#",
"langSlug": "csharp",
"code": "public class Solution {\n public string GetPermutation(int n, int k) {\n\n }\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "JavaScript",
"langSlug": "javascript",
"code": "/**\n * @param {number} n\n * @param {number} k\n * @return {string}\n */\nvar getPermutation = function(n, k) {\n\n};",
"__typename": "CodeSnippetNode"
},
{
2023-12-09 18:42:21 +08:00
"lang": "TypeScript",
"langSlug": "typescript",
"code": "function getPermutation(n: number, k: number): string {\n \n};",
"__typename": "CodeSnippetNode"
},
{
"lang": "PHP",
"langSlug": "php",
"code": "class Solution {\n\n /**\n * @param Integer $n\n * @param Integer $k\n * @return String\n */\n function getPermutation($n, $k) {\n\n }\n}",
2022-03-27 20:56:26 +08:00
"__typename": "CodeSnippetNode"
},
{
"lang": "Swift",
"langSlug": "swift",
"code": "class Solution {\n func getPermutation(_ n: Int, _ k: Int) -> String {\n\n }\n}",
"__typename": "CodeSnippetNode"
},
{
2023-12-09 18:42:21 +08:00
"lang": "Kotlin",
"langSlug": "kotlin",
"code": "class Solution {\n fun getPermutation(n: Int, k: Int): String {\n\n }\n}",
2022-03-27 20:56:26 +08:00
"__typename": "CodeSnippetNode"
},
{
2023-12-09 18:42:21 +08:00
"lang": "Dart",
"langSlug": "dart",
"code": "class Solution {\n String getPermutation(int n, int k) {\n \n }\n}",
2022-03-27 20:56:26 +08:00
"__typename": "CodeSnippetNode"
},
{
2023-12-09 18:42:21 +08:00
"lang": "Go",
"langSlug": "golang",
"code": "func getPermutation(n int, k int) string {\n\n}",
2022-03-27 20:56:26 +08:00
"__typename": "CodeSnippetNode"
},
{
2023-12-09 18:42:21 +08:00
"lang": "Ruby",
"langSlug": "ruby",
"code": "# @param {Integer} n\n# @param {Integer} k\n# @return {String}\ndef get_permutation(n, k)\n\nend",
2022-03-27 20:56:26 +08:00
"__typename": "CodeSnippetNode"
},
{
2023-12-09 18:42:21 +08:00
"lang": "Scala",
"langSlug": "scala",
"code": "object Solution {\n def getPermutation(n: Int, k: Int): String = {\n\n }\n}",
2022-03-27 20:56:26 +08:00
"__typename": "CodeSnippetNode"
},
{
2023-12-09 18:42:21 +08:00
"lang": "Rust",
"langSlug": "rust",
"code": "impl Solution {\n pub fn get_permutation(n: i32, k: i32) -> String {\n\n }\n}",
2022-03-27 20:56:26 +08:00
"__typename": "CodeSnippetNode"
},
{
"lang": "Racket",
"langSlug": "racket",
2023-12-09 18:42:21 +08:00
"code": "(define/contract (get-permutation n k)\n (-> exact-integer? exact-integer? string?)\n )",
2022-03-27 20:56:26 +08:00
"__typename": "CodeSnippetNode"
},
{
"lang": "Erlang",
"langSlug": "erlang",
"code": "-spec get_permutation(N :: integer(), K :: integer()) -> unicode:unicode_binary().\nget_permutation(N, K) ->\n .",
"__typename": "CodeSnippetNode"
},
{
"lang": "Elixir",
"langSlug": "elixir",
2023-12-09 18:42:21 +08:00
"code": "defmodule Solution do\n @spec get_permutation(n :: integer, k :: integer) :: String.t\n def get_permutation(n, k) do\n \n end\nend",
2022-03-27 20:56:26 +08:00
"__typename": "CodeSnippetNode"
}
],
2023-12-09 19:57:46 +08:00
"stats": "{\"totalAccepted\": \"135.9K\", \"totalSubmission\": \"253.8K\", \"totalAcceptedRaw\": 135896, \"totalSubmissionRaw\": 253834, \"acRate\": \"53.5%\"}",
2022-03-27 20:56:26 +08:00
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "3\n3",
"metaData": "{\r\n \"name\": \"getPermutation\",\r\n \"params\": [\r\n {\r\n \"name\": \"n\",\r\n \"type\": \"integer\"\r\n },\r\n {\r\n \"name\": \"k\",\r\n \"type\": \"integer\"\r\n }\r\n ],\r\n \"return\": {\r\n \"type\": \"string\"\r\n }\r\n}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [],
"enableRunCode": true,
2023-12-09 18:42:21 +08:00
"envInfo": "{\"cpp\":[\"C++\",\"<p>\\u7248\\u672c\\uff1a<code>clang 11<\\/code> \\u91c7\\u7528\\u6700\\u65b0C++ 20\\u6807\\u51c6\\u3002<\\/p>\\r\\n\\r\\n<p>\\u7f16\\u8bd1\\u65f6\\uff0c\\u5c06\\u4f1a\\u91c7\\u7528<code>-O2<\\/code>\\u7ea7\\u4f18\\u5316\\u3002<a href=\\\"https:\\/\\/github.com\\/google\\/sanitizers\\/wiki\\/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer<\\/a> \\u4e5f\\u88ab\\u5f00\\u542f\\u6765\\u68c0\\u6d4b<code>out-of-bounds<\\/code>\\u548c<code>use-after-free<\\/code>\\u9519\\u8bef\\u3002<\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u4f7f\\u7528\\u65b9\\u4fbf\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8\\u5bfc\\u5165\\u3002<\\/p>\"],\"java\":[\"Java\",\"<p>\\u7248\\u672c\\uff1a<code>OpenJDK 17<\\/code>\\u3002\\u53ef\\u4ee5\\u4f7f\\u7528Java 8\\u7684\\u7279\\u6027\\u4f8b\\u5982\\uff0clambda expressions \\u548c stream API\\u3002<\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u65b9\\u4fbf\\u8d77\\u89c1\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u88ab\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u5305\\u542b Pair \\u7c7b: https:\\/\\/docs.oracle.com\\/javase\\/8\\/javafx\\/api\\/javafx\\/util\\/Pair.html <\\/p>\"],\"python\":[\"Python\",\"<p>\\u7248\\u672c\\uff1a <code>Python 2.7.12<\\/code><\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u65b9\\u4fbf\\u8d77\\u89c1\\uff0c\\u5927\\u90e8\\u5206\\u5e38\\u7528\\u5e93\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8 \\u5bfc\\u5165\\uff0c\\u5982\\uff1a<a href=\\\"https:\\/\\/docs.python.org\\/2\\/library\\/array.html\\\" target=\\\"_blank\\\">array<\\/a>, <a href=\\\"https:\\/\\/docs.python.org\\/2\\/library\\/bisect.html\\\" target=\\\"_blank\\\">bisect<\\/a>, <a href=\\\"https:\\/\\/docs.python.org\\/2\\/library\\/collections.html\\\" target=\\\"_blank\\\">collections<\\/a>\\u3002\\u5982\\u679c\\u60a8\\u9700\\u8981\\u4f7f\\u7528\\u5176\\u4ed6\\u5e93\\u51fd\\u6570\\uff0c\\u8bf7\\u81ea\\u884c\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u6ce8\\u610f Python 2.7 <a href=\\\"https:\\/\\/www.python.org\\/dev\\/peps\\/pep-0373\\/\\\" target=\\\"_blank\\\">\\u5c06\\u57282020\\u5e74\\u540e\\u4e0d\\u518d\\u7ef4\\u62a4<\\/a>\\u3002 \\u5982\\u60f3\\u4f7f\\u7528\\u6700\\u65b0\\u7248\\u7684Python\\uff0c\\u8bf7\\u9009\\u62e9Python 3\\u3002<\\/p>\"],\"c\":[\"C\",\"<p>\\u7248\\u672c\\uff1a<code>GCC 8.2<\\/code>\\uff0c\\u91c7\\u7528GNU11\\u6807\\u51c6\\u3002<\\/p>\\r\\n\\r\\n<p>\\u7f16\\u8bd1\\u65f6\\uff0c\\u5c06\\u4f1a\\u91c7\\u7528<code>-O1<\\/code>\\u7ea7\\u4f18\\u5316\\u3002 <a href=\\\"https:\\/\\/github.com\\/google\\/sanitizers\\/wiki\\/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer<\\/a>\\u4e5f\\u88ab\\u5f00\\u542f\\u6765\\u68c0\\u6d4b<code>out-of-bounds<\\/code>\\u548c<code>use-after-free<\\/code>\\u9519\\u8bef\\u3002<\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u4f7f\\u7528\\u65b9\\u4fbf\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u5982\\u60f3\\u4f7f\\u7528\\u54c8\\u5e0c\\u8868\\u8fd0\\u7b97, \\u60a8\\u53ef\\u4ee5\\u4f7f\\u7528 <a href=\\\"https:\\/\\/troydhanson.github.io\\/uthash\\/\\\" target=\\\"_blank\\\">uthash<\\/a>\\u3002 \\\"uthash.h\\\"\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5bfc\\u5165\\u3002\\u8bf7\\u770b\\u5982\\u4e0b\\u793a\\u4f8b:<\\/p>\\r\\n\\r\\n<p><b>1. \\u5f80\\u54c8\\u5e0c\\u8868\\u4e2d\\u6dfb\\u52a0\\u4e00\\u4e2a\\u5bf9\\u8c61\\uff1a<\\/b>\\r\\n<pre>\\r\\nstruct hash_entry {\\r\\n int id; \\/* we'll use this field as the key *\\/\\r\\n char name[10];\\r\\n UT_hash_handle hh; \\/* makes this structure hashable *\\/\\r\\n};\\r\\n\\r\\nstruct hash_entry *users = NULL;\\r\\n\\r\\nvoid add_user(struct hash_entry *s) {\\r\\n HASH_ADD_INT(users, id, s);\\r\\n}\\r\\n<\\/pre>\\r\\n<\\/p>\\r\\n\\r\\n<p><b>2. \\u5728\\u54c8\\u5e0c\\u8868\\u4e2d\\u67e5\\u627e\\u4e00\\u4e2a\\u5bf9\\u8c61\\uff1a<\\/b>\\r\\n<pre>\\r\\nstruct hash_entry *find_user(int user_id) {\\r\\n struct hash_entry *s;\\r\\n HASH_FIND_INT(users, &user_id, s);\\r\\n re
2022-03-27 20:56:26 +08:00
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "3\n3\n4\n9\n3\n1",
"__typename": "QuestionNode"
}
}
}