{"id":2294,"date":"2022-01-23T14:46:03","date_gmt":"2022-01-23T06:46:03","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2294"},"modified":"2022-01-23T15:15:25","modified_gmt":"2022-01-23T07:15:25","slug":"leetcodeday60","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/23\/leetcodeday60\/","title":{"rendered":"leetcodeday60 &#8211;\u6392\u5217\u5e8f\u5217"},"content":{"rendered":"\n<p>\u7ed9\u51fa\u96c6\u5408&nbsp;<code>[1,2,3,...,n]<\/code>\uff0c\u5176\u6240\u6709\u5143\u7d20\u5171\u6709&nbsp;<code>n!<\/code>&nbsp;\u79cd\u6392\u5217\u3002<\/p>\n\n\n\n<p>\u6309\u5927\u5c0f\u987a\u5e8f\u5217\u51fa\u6240\u6709\u6392\u5217\u60c5\u51b5\uff0c\u5e76\u4e00\u4e00\u6807\u8bb0\uff0c\u5f53&nbsp;<code>n = 3<\/code>&nbsp;\u65f6, \u6240\u6709\u6392\u5217\u5982\u4e0b\uff1a<\/p>\n\n\n\n<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>\n\n\n\n<p>\u7ed9\u5b9a&nbsp;<code>n<\/code>&nbsp;\u548c&nbsp;<code>k<\/code>\uff0c\u8fd4\u56de\u7b2c&nbsp;<code>k<\/code>&nbsp;\u4e2a\u6392\u5217\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>n = 3, k = 3\n<strong>\u8f93\u51fa\uff1a<\/strong>\"213\"<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>n = 4, k = 9\n<strong>\u8f93\u51fa\uff1a<\/strong>\"2314\"<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 3\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>n = 3, k = 1\n<strong>\u8f93\u51fa\uff1a<\/strong>\"123\"<\/code><\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul><li><code>1 &lt;= n &lt;= 9<\/code><\/li><li><code>1 &lt;= k &lt;= n!<\/code><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=60 lang=python3\r\n#\r\n# &#91;60] \u6392\u5217\u5e8f\u5217\r\n#\r\n\r\n# @lc code=start\r\nclass Solution:\r\n    def getPermutation(self, n: int, k: int) -> str:\r\n        nums=&#91;i for i in range(1,n+1)]\r\n\r\n        def subgetPermutation(N,k,nums,str1): \r\n          import math\r\n            #print(k)\r\n          while 1:\r\n            if k&lt;0 or len(nums)==1: \r\n                str1=str1+str(nums&#91;0])\r\n                return str1\r\n            x=math.factorial(N-1)\r\n            for i in range(1,len(nums)+1):\r\n                if i*x>=k:    \r\n                    k=k-(i-1)*x if k-(i-1)*x>0 else k\r\n                    N=N-1\r\n                    #print(i,k,N,nums)\r\n\r\n                    str1=str1+str(nums&#91;i-1])\r\n                    #print(str1)\r\n                    nums.remove(nums&#91;i-1])\r\n                    #print(nums)\r\n                    break\r\n        return subgetPermutation(n,k,nums,\"\")\r\n# @lc code=end\r\n<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-272.png\" alt=\"\" class=\"wp-image-2295\" width=\"578\" height=\"144\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-272.png 877w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-272-300x75.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-272-768x192.png 768w\" sizes=\"(max-width: 578px) 100vw, 578px\" \/><\/figure><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u51fa\u96c6\u5408&nbsp;[1,2,3,&#8230;,n]\uff0c\u5176\u6240\u6709\u5143\u7d20\u5171\u6709&nbsp;n!&nbsp;\u79cd\u6392\u5217\u3002 \u6309\u5927\u5c0f\u987a\u5e8f &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/23\/leetcodeday60\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday60 &#8211;\u6392\u5217\u5e8f\u5217<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2294"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=2294"}],"version-history":[{"count":1,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2294\/revisions"}],"predecessor-version":[{"id":2296,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2294\/revisions\/2296"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2294"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}