{"id":2349,"date":"2022-01-24T15:38:35","date_gmt":"2022-01-24T07:38:35","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2349"},"modified":"2022-01-24T15:38:37","modified_gmt":"2022-01-24T07:38:37","slug":"leetcodeday24-2","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/24\/leetcodeday24-2\/","title":{"rendered":"leetcodeday24 &#8211;\u4e24\u4e24\u4ea4\u6362\u94fe\u8868\u4e2d\u7684\u8282\u70b9"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\uff0c\u4e24\u4e24\u4ea4\u6362\u5176\u4e2d\u76f8\u90bb\u7684\u8282\u70b9\uff0c\u5e76\u8fd4\u56de\u4ea4\u6362\u540e\u94fe\u8868\u7684\u5934\u8282\u70b9\u3002\u4f60\u5fc5\u987b\u5728\u4e0d\u4fee\u6539\u8282\u70b9\u5185\u90e8\u7684\u503c\u7684\u60c5\u51b5\u4e0b\u5b8c\u6210\u672c\u9898\uff08\u5373\uff0c\u53ea\u80fd\u8fdb\u884c\u8282\u70b9\u4ea4\u6362\uff09\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img src=\"https:\/\/assets.leetcode.com\/uploads\/2020\/10\/03\/swap_ex1.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>head = &#91;1,2,3,4]\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;2,1,4,3]<\/code><\/pre>\n\n\n\n<p>\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># &#91;24] \u4e24\u4e24\u4ea4\u6362\u94fe\u8868\u4e2d\u7684\u8282\u70b9\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 swapPairs(self, head: ListNode) -> ListNode:\r\n        # head0 = ListNode(0,head)\r\n        if head==None or head.next==None:\r\n            return head\r\n        head0=head\r\n        headr=head.next\r\n\r\n        while head0!=None:\r\n            head1=head0\r\n            head2=head0.next\r\n            head3=head2.next\r\n            #print(head3.val)\r\n            head2.next=head1\r\n            if head3==None:    \r\n                head1.next=None\r\n                #print(\"is 1\")\r\n                return headr\r\n            if head3.next==None:\r\n                head1.next=head3\r\n                #print(\"is 2\")\r\n\r\n                return headr\r\n            else:\r\n                head1.next=head3.next\r\n                #print(head3.val)\r\n                #print(\"is 0\")\r\n\r\n                head0=head3\r\n                #print(head0.val)\r\n        return headr\r\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"929\" height=\"234\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-283.png\" alt=\"\" class=\"wp-image-2350\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-283.png 929w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-283-300x76.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-283-768x193.png 768w\" sizes=\"(max-width: 929px) 100vw, 929px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\uff0c\u4e24\u4e24\u4ea4\u6362\u5176\u4e2d\u76f8\u90bb\u7684\u8282\u70b9\uff0c\u5e76\u8fd4\u56de\u4ea4\u6362\u540e\u94fe\u8868\u7684\u5934\u8282\u70b9\u3002\u4f60\u5fc5\u987b\u5728\u4e0d\u4fee\u6539\u8282\u70b9\u5185\u90e8\u7684\u503c\u7684\u60c5\u51b5\u4e0b\u5b8c\u6210\u672c\u9898\uff08\u5373 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/24\/leetcodeday24-2\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday24 &#8211;\u4e24\u4e24\u4ea4\u6362\u94fe\u8868\u4e2d\u7684\u8282\u70b9<\/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\/2349"}],"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=2349"}],"version-history":[{"count":1,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2349\/revisions"}],"predecessor-version":[{"id":2351,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2349\/revisions\/2351"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2349"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}