{"id":2297,"date":"2022-01-23T17:11:38","date_gmt":"2022-01-23T09:11:38","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2297"},"modified":"2022-01-23T17:11:39","modified_gmt":"2022-01-23T09:11:39","slug":"leetcodeday61","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/23\/leetcodeday61\/","title":{"rendered":"leetcodeday61&#8211;\u65cb\u8f6c\u94fe\u8868"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\u7684\u5934\u8282\u70b9&nbsp;<code>head<\/code>&nbsp;\uff0c\u65cb\u8f6c\u94fe\u8868\uff0c\u5c06\u94fe\u8868\u6bcf\u4e2a\u8282\u70b9\u5411\u53f3\u79fb\u52a8&nbsp;<code>k<\/code>\u4e2a\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" src=\"https:\/\/assets.leetcode.com\/uploads\/2020\/11\/13\/rotate1.jpg\" alt=\"\" width=\"402\" height=\"170\"\/><\/figure><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>head = &#91;1,2,3,4,5], k = 2\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;4,5,1,2,3]<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" src=\"https:\/\/assets.leetcode.com\/uploads\/2020\/11\/13\/roate2.jpg\" alt=\"\" width=\"236\" height=\"271\"\/><\/figure><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>head = &#91;0,1,2], k = 4\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;2,0,1]<\/code><\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul><li>\u94fe\u8868\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u5728\u8303\u56f4&nbsp;<code>[0, 500]<\/code>&nbsp;\u5185<\/li><li><code>-100 &lt;= Node.val &lt;= 100<\/code><\/li><li><code>0 &lt;= k &lt;= 2 * 10<sup>9<\/sup><\/code><\/li><\/ul>\n\n\n\n<p>\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=61 lang=python3\r\n#\r\n# &#91;61] \u65cb\u8f6c\u94fe\u8868\r\n#\r\n\r\n# @lc code=start\r\n# Definition for singly-linked list.\r\n# class ListNode:\r\n#     def __init__(self, val=0, next=None):\r\n#         self.val = val\r\n#         self.next = next\r\nclass Solution:\r\n    def rotateRight(self, head: Optional&#91;ListNode], k: int) -> Optional&#91;ListNode]:\r\n        def lenlink(head):\r\n            i=0\r\n            while head != None:\r\n                head=head.next\r\n                i=i+1\r\n            return i\r\n        lens=lenlink(head)\r\n        if lens==0:\r\n            return head\r\n        k=k%(lens) \r\n        newlist=ListNode(0,None)\r\n        newcur=newlist\r\n        cur1 = head\r\n        cur2 = head\r\n        for i in range(lens-k):\r\n            cur1=cur1.next\r\n            #print(cur1.val)\r\n        for i in range(lens):\r\n            if i &lt; k:\r\n               newcur.val= cur1.val\r\n               print(newcur.val)\r\n               cur1=cur1.next\r\n               newcur.next=ListNode(0,None)\r\n               newcur=newcur.next\r\n            \r\n            else:\r\n               newcur.val= cur2.val\r\n               #print(cur2.val)\r\n               cur2=cur2.next\r\n               if i&lt;lens-1:\r\n                    newcur.next=ListNode(0,None)\r\n               newcur=newcur.next \r\n        return newlist\r\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"807\" height=\"226\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-273.png\" alt=\"\" class=\"wp-image-2298\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-273.png 807w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-273-300x84.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-273-768x215.png 768w\" sizes=\"(max-width: 807px) 100vw, 807px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\u7684\u5934\u8282\u70b9&nbsp;head&nbsp;\uff0c\u65cb\u8f6c\u94fe\u8868\uff0c\u5c06\u94fe\u8868\u6bcf\u4e2a\u8282\u70b9\u5411\u53f3\u79fb\u52a8&nbsp;k\u4e2a\u4f4d\u7f6e\u3002  &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/23\/leetcodeday61\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday61&#8211;\u65cb\u8f6c\u94fe\u8868<\/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\/2297"}],"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=2297"}],"version-history":[{"count":3,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2297\/revisions"}],"predecessor-version":[{"id":2301,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2297\/revisions\/2301"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2297"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}