{"id":3096,"date":"2020-02-29T12:24:14","date_gmt":"2020-02-29T04:24:14","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=3096"},"modified":"2020-02-29T12:24:14","modified_gmt":"2020-02-29T04:24:14","slug":"%e3%80%90leetcode%e3%80%910075-%e9%a2%9c%e8%89%b2%e5%88%86%e7%b1%bb","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/algorithm\/3096\/","title":{"rendered":"\u3010LeetCode\u30110075 \u989c\u8272\u5206\u7c7b"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/sort-colors\/\">https:\/\/leetcode-cn.com\/problems\/sort-colors\/<\/a><\/p>\n\n\n<pre class=\"wp-block-preformatted\"># -*- coding:utf-8 -*-\n<em>\n<\/em>class Solution(object):\n    def sortColors(self, nums):\n        <em>\"\"\"\n        <\/em><strong><em>:type<\/em><\/strong><em> nums: List[int]\n        <\/em><strong><em>:rtype<\/em><\/strong><em>: None Do not return anything, modify nums in-place instead.\n        \"\"\"\n        <\/em>n = len(nums)\n        for i in range(n):\n            for j in range(i, n):\n                if nums[i] > nums[j]:\n                    nums[i], nums[j] = nums[j], nums[i]\n        return nums\nif __name__ == '__main__':\n    nums = [2, 0, 2, 1, 1, 0]\n    print(Solution().sortColors(nums))\n<\/pre>\n\n\n<p><strong>\u601d\u8def<\/strong>\uff1a \u8fd9\u9053\u9898\u5e94\u8be5\u662f\u7ecf\u5178\u7684\u8377\u5170\u56fd\u65d7\u95ee\u9898\uff08\u867d\u7136\u4e5f\u662f\u6211\u540e\u6765\u624d\u77e5\u9053\u7684233\uff09\uff0c\u4ece\u9898\u610f\u6765\u8bf4\uff0c\u8fd9\u9053\u9898\u53ea\u8981\u8fdb\u884c\u4e00\u4e0b\u6392\u5e8f\u5c31\u53ef\u4ee5\u4e86\uff0c\u56e0\u4e3a\u6570\u5b57\u6bd4\u8f83\u5c0f\uff0c\u4e5f\u56e0\u4e3a\u61d2\uff0c\u5c31\u6ca1\u5199\u5feb\u6392\u7528\u7684\u5192\u6ce1\u3002<\/p>\n\n\n<p>\u4ece\u8fd9\u9053\u9898\u8fd8\u4e86\u89e3\u4e86\u53cc\u8def\u5feb\u6392\u4e09\u8def\u5feb\u6392\u3002<\/p>\n\n\n<p>\u6b63\u5e38\u7684\u5feb\u901f\u6392\u5e8f\u662f\u6bcf\u4e00\u8d9f\u90fd\u4f1a\u6709\u4e00\u4e2a\u5143\u7d20\u653e\u5728\u6700\u540e\u7684\u4f4d\u7f6e\uff0c\u5728\u8fd9\u4e2a\u5143\u7d20\u5de6\u53f3\u7684\u5143\u7d20\u4f9d\u7136\u662f\u65e0\u5e8f\u6392\u5217\u3002<\/p>\n\n\n<p>\u800c\u53cc\u8def\u6392\u5e8f\u4e0d\u4ec5\u4f1a\u5c06\u4e00\u4e2a\u5143\u7d20\u653e\u5728\u6700\u540e\u7684\u4f4d\u7f6e\uff0c\u8fd8\u4f1a\u5bf9\u5176\u4ed6\u5143\u7d20\u8fdb\u884c\u4e00\u4e2a\u5927\u6982\u7684\u6392\u5e8f\uff0c\u6bd4\u5173\u952e\u5b57\u5c0f\u7684\u5728\u5173\u952e\u5b57\u5de6\u8fb9\uff0c\u6bd4\u5173\u952e\u5b57\u5927\u7684\u5728\u53f3\u8fb9\u3002\uff08\u4e5f\u5c31\u662f\u8bf4\u6bd4\u5173\u952e\u5b57\u5c0f\u7684\u76f4\u63a5\u6254\u5230\u8868\u5934\uff0c\u6bd4\u5173\u952e\u5b57\u5927\u7684\u76f4\u63a5\u6254\u5230\u8868\u5c3e\uff09\u3002<\/p>\n\n\n<p>\u4e09\u8def\u6392\u5e8f\u5c31\u66f4\u5389\u5bb3\u4e86\uff0c\u4e0d\u4ec5\u627e\u6bd4\u5173\u952e\u5b57\u5927\u7684\uff0c\u6bd4\u5173\u952e\u5b57\u5c0f\u7684\uff0c\u8fd8\u548c\u5173\u952e\u5b57\u4e00\u6837\u5927\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/leetcode-cn.com\/problems\/sort-colors\/ # -* [&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":3508,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/3096"}],"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=3096"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/3096\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=3096"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=3096"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=3096"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}