{"id":2412,"date":"2022-01-26T15:48:06","date_gmt":"2022-01-26T07:48:06","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2412"},"modified":"2022-01-26T15:48:08","modified_gmt":"2022-01-26T07:48:08","slug":"leetcodeday86","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/26\/leetcodeday86\/","title":{"rendered":"leetcodeday86 &#8211;\u5206\u9694\u94fe\u8868"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\u7684\u5934\u8282\u70b9&nbsp;<code>head<\/code>&nbsp;\u548c\u4e00\u4e2a\u7279\u5b9a\u503c<em>&nbsp;<\/em><code>x<\/code>&nbsp;\uff0c\u8bf7\u4f60\u5bf9\u94fe\u8868\u8fdb\u884c\u5206\u9694\uff0c\u4f7f\u5f97\u6240\u6709&nbsp;<strong>\u5c0f\u4e8e<\/strong>&nbsp;<code>x<\/code>&nbsp;\u7684\u8282\u70b9\u90fd\u51fa\u73b0\u5728&nbsp;<strong>\u5927\u4e8e\u6216\u7b49\u4e8e<\/strong>&nbsp;<code>x<\/code>&nbsp;\u7684\u8282\u70b9\u4e4b\u524d\u3002<\/p>\n\n\n\n<p>\u4f60\u5e94\u5f53&nbsp;<strong>\u4fdd\u7559<\/strong>&nbsp;\u4e24\u4e2a\u5206\u533a\u4e2d\u6bcf\u4e2a\u8282\u70b9\u7684\u521d\u59cb\u76f8\u5bf9\u4f4d\u7f6e\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\/2021\/01\/04\/partition.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>head = [1,4,3,2,5,2], x = 3\n<strong>\u8f93\u51fa<\/strong>\uff1a[1,2,2,4,3,5]\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>head = [2,1], x = 2\n<strong>\u8f93\u51fa<\/strong>\uff1a[1,2]\n<\/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, 200]<\/code>&nbsp;\u5185<\/li><li><code>-100 &lt;= Node.val &lt;= 100<\/code><\/li><li><code>-200 &lt;= x &lt;= 200<\/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=86 lang=python3\r\n#\r\n# &#91;86] \u5206\u9694\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 partition(self, head: ListNode, x: int) -> ListNode:\r\n        head1=ListNode(0,None)\r\n        cur1=head1\r\n        head2=ListNode(0,None)\r\n        cur2=head2\r\n        head3=head\r\n        while head3!=None:\r\n            #print(head3.val)\r\n            if head3.val&lt;x:\r\n                cur1.next=ListNode(head3.val,None)\r\n                head3=head3.next\r\n                cur1=cur1.next\r\n\r\n            else:\r\n                cur2.next=ListNode(head3.val,None)\r\n                head3=head3.next\r\n                cur2=cur2.next\r\n        cur1.next=head2.next\r\n        return head1.next\r\n\r\n\r\n# @lc code=end\r\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"862\" height=\"255\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-296.png\" alt=\"\" class=\"wp-image-2415\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-296.png 862w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-296-300x89.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-296-768x227.png 768w\" sizes=\"(max-width: 862px) 100vw, 862px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\u7684\u5934\u8282\u70b9&nbsp;head&nbsp;\u548c\u4e00\u4e2a\u7279\u5b9a\u503c&nbsp;x&nbsp;\uff0c\u8bf7\u4f60\u5bf9\u94fe\u8868\u8fdb\u884c\u5206\u9694 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/26\/leetcodeday86\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday86 &#8211;\u5206\u9694\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\/2412"}],"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=2412"}],"version-history":[{"count":3,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2412\/revisions"}],"predecessor-version":[{"id":2416,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2412\/revisions\/2416"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2412"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}