{"id":2383,"date":"2022-01-25T15:46:41","date_gmt":"2022-01-25T07:46:41","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2383"},"modified":"2022-01-25T15:46:42","modified_gmt":"2022-01-25T07:46:42","slug":"leetcodeday75","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/25\/leetcodeday75\/","title":{"rendered":"leetcodeday75 &#8211;\u989c\u8272\u5206\u7c7b"},"content":{"rendered":"\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u7ea2\u8272\u3001\u767d\u8272\u548c\u84dd\u8272\uff0c\u4e00\u5171&nbsp;<code>n<\/code>\u4e2a\u5143\u7d20\u7684\u6570\u7ec4\uff0c<strong><a href=\"https:\/\/baike.baidu.com\/item\/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95\" target=\"_blank\" rel=\"noreferrer noopener\">\u539f\u5730<\/a><\/strong>\u5bf9\u5b83\u4eec\u8fdb\u884c\u6392\u5e8f\uff0c\u4f7f\u5f97\u76f8\u540c\u989c\u8272\u7684\u5143\u7d20\u76f8\u90bb\uff0c\u5e76\u6309\u7167\u7ea2\u8272\u3001\u767d\u8272\u3001\u84dd\u8272\u987a\u5e8f\u6392\u5217\u3002<\/p>\n\n\n\n<p>\u6b64\u9898\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u6574\u6570&nbsp;<code>0<\/code>\u3001&nbsp;<code>1<\/code>&nbsp;\u548c&nbsp;<code>2<\/code>&nbsp;\u5206\u522b\u8868\u793a\u7ea2\u8272\u3001\u767d\u8272\u548c\u84dd\u8272\u3002<\/p>\n\n\n\n<ul><li><\/li><\/ul>\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>nums = &#91;2,0,2,1,1,0]\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;0,0,1,1,2,2]<\/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>nums = &#91;2,0,1]\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;0,1,2]\n<\/code><\/pre>\n\n\n\n<p>\u5feb\u901f\u6392\u5e8f\uff1a\u9009\u5b9a\u57fa\u51c6\uff0c\u5927\u4e8e\u57fa\u51c6\u7684\u5728\u53f3\u8fb9\uff0c\u5c0f\u4e8e\u57fa\u51c6\u7684\u5728\u5de6\u8fb9<\/p>\n\n\n\n<p>\u5feb\u901f\u6392\u5e8f(Quick Sort)\u662f\u5bf9\u5192\u6ce1\u6392\u5e8f\u7684\u4e00\u79cd\u6539\u8fdb\uff0c\u5176\u7684\u57fa\u672c\u601d\u60f3:\u9009\u4e00\u57fa\u51c6\u5143\u7d20\uff0c\u4f9d\u6b21\u5c06\u5269\u4f59\u5143\u7d20\u4e2d\u5c0f\u4e8e\u8be5\u57fa\u51c6\u5143\u7d20\u7684\u503c\u653e\u7f6e\u5176\u5de6\u4fa7\uff0c\u5927\u4e8e\u7b49\u4e8e\u8be5\u57fa\u51c6\u5143\u7d20\u7684\u503c\u653e\u7f6e\u5176\u53f3\u4fa7\uff1b\u7136\u540e\uff0c\u53d6\u57fa\u51c6\u5143\u7d20\u7684\u524d\u534a\u90e8\u5206\u548c\u540e\u534a\u90e8\u5206\u5206\u522b\u8fdb\u884c\u540c\u6837\u7684\u5904\u7406\uff1b\u4ee5\u6b64\u7c7b\u63a8\uff0c\u76f4\u81f3\u5404\u5b50\u5e8f\u5217\u5269\u4f59\u4e00\u4e2a\u5143\u7d20\u65f6\uff0c\u5373\u6392\u5e8f\u5b8c\u6210\uff08\u7c7b\u6bd4\u4e8c\u53c9\u6811\u7684\u601d\u60f3)\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=75 lang=python3\r\n#\r\n# &#91;75] \u989c\u8272\u5206\u7c7b\r\n#\r\n\r\n# @lc code=start\r\nclass Solution:\r\n    def sortColors(self, nums: List&#91;int]) -> None:\r\n        \"\"\"\r\n        Do not return anything, modify nums in-place instead.\r\n        \"\"\"\r\n        def quick_sort(lists,i,j):\r\n            if i >= j:\r\n                return list\r\n            pivot = lists&#91;i]\r\n            low = i\r\n            high = j\r\n            while i &lt; j:\r\n                while i &lt; j and lists&#91;j] >= pivot:\r\n                    j -= 1\r\n                lists&#91;i]=lists&#91;j]\r\n                while i &lt; j and lists&#91;i] &lt;=pivot:\r\n                    i += 1\r\n                lists&#91;j]=lists&#91;i]\r\n            lists&#91;j] = pivot\r\n            quick_sort(lists,low,i-1)\r\n            quick_sort(lists,i+1,high)\r\n            return lists\r\n\r\n        quick_sort(nums,0, len(nums) - 1)\r\n# @lc code=end<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"633\" height=\"262\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-291.png\" alt=\"\" class=\"wp-image-2384\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-291.png 633w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-291-300x124.png 300w\" sizes=\"(max-width: 633px) 100vw, 633px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u7ea2\u8272\u3001\u767d\u8272\u548c\u84dd\u8272\uff0c\u4e00\u5171&nbsp;n\u4e2a\u5143\u7d20\u7684\u6570\u7ec4\uff0c\u539f\u5730\u5bf9\u5b83\u4eec\u8fdb\u884c\u6392\u5e8f\uff0c\u4f7f\u5f97\u76f8\u540c\u989c\u8272\u7684\u5143\u7d20\u76f8\u90bb\uff0c\u5e76\u6309 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/25\/leetcodeday75\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday75 &#8211;\u989c\u8272\u5206\u7c7b<\/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\/2383"}],"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=2383"}],"version-history":[{"count":3,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2383\/revisions"}],"predecessor-version":[{"id":2387,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2383\/revisions\/2387"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2383"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}