{"id":2812,"date":"2020-01-26T11:48:00","date_gmt":"2020-01-26T03:48:00","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=2812"},"modified":"2020-01-26T11:48:00","modified_gmt":"2020-01-26T03:48:00","slug":"%e3%80%90leetcode%e3%80%910024-%e4%b8%a4%e4%b8%a4%e4%ba%a4%e6%8d%a2%e9%93%be%e8%a1%a8%e4%b8%ad%e7%9a%84%e8%8a%82%e7%82%b9","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/algorithm\/2812\/","title":{"rendered":"\u3010LeetCode\u30110024 \u4e24\u4e24\u4ea4\u6362\u94fe\u8868\u4e2d\u7684\u8282\u70b9"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/swap-nodes-in-pairs\/\">https:\/\/leetcode-cn.com\/problems\/swap-nodes-in-pairs\/<\/a><\/p>\n\n\n<pre class=\"wp-block-code\"><code># -*- coding:utf-8 -*-\n# Definition for singly-linked list.\nclass ListNode(object):\n    def __init__(self, x):\n        self.val = x\n        self.next = None\nclass Solution(object):\n    def swapPairs(self, head):\n        \"\"\"\n        :type head: ListNode\n        :rtype: ListNode\n        \"\"\"\n        if head is None:\n            return\n        node = head.next\n        if node is None:\n            return head\n        head.next = node.next\n        node.next = head\n        head.next = self.swapPairs(head.next)\n        return node\nif __name__ == '__main__':\n    n1 = ListNode(1)\n    n2 = ListNode(2)\n    n3 = ListNode(3)\n    n4 = ListNode(4)\n    n1.next = n2\n    n2.next = n3\n    n3.next = n4\n    print(Solution().swapPairs(n1))\n<\/code><\/pre>\n\n\n<p><strong>\u601d\u8def<\/strong>\uff1a\u6bcf\u6b21\u4ea4\u6362\u4e24\u4e2a\u4e34\u8fd1\u7684\u94fe\u8868\uff0c\u7136\u540e\u5411\u4e0b\u9012\u5f52\u3002\u8fb9\u754c\u6761\u4ef6\u5c31\u662f\u5269\u4e00\u4e2a\u8282\u70b9\uff08\u603b\u8282\u70b9\u6570\u4e3a\u5947\u6570\uff09\uff0c\u76f4\u63a5\u8fd4\u56dehead\u5373\u53ef\uff0c\u6b63\u597d\u4e24\u4e24\u4ea4\u6362\uff08\u8fd9\u79cd\u7684\u8bdd\u9012\u5f52\u7684head\u5c31\u4e3a\u7a7a\uff09\u76f4\u63a5\u8fd4\u56de\u7a7a\u5373\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/leetcode-cn.com\/problems\/swap-nodes-in-pai [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[10],"tags":[],"views":1654,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2812"}],"collection":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2812"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2812\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2812"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}