{"id":2975,"date":"2020-02-19T12:18:52","date_gmt":"2020-02-19T04:18:52","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=2975"},"modified":"2020-02-19T12:18:52","modified_gmt":"2020-02-19T04:18:52","slug":"%e3%80%90leetcode%e3%80%910059-%e8%9e%ba%e6%97%8b%e7%9f%a9%e9%98%b5-ii","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/algorithm\/2975\/","title":{"rendered":"\u3010LeetCode\u30110059 \u87ba\u65cb\u77e9\u9635 II"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/spiral-matrix-ii\/\">https:\/\/leetcode-cn.com\/problems\/spiral-matrix-ii\/<\/a><\/p>\n\n\n<pre class=\"wp-block-preformatted\"># -*- coding:utf-8 -*-\n<em>\n<\/em>class Solution(object):\n    def generateMatrix(self, n):\n        <em>\"\"\"\n        <\/em><strong><em>:type<\/em><\/strong><em> n: int\n        <\/em><strong><em>:rtype<\/em><\/strong><em>: List[List[int]]\n        \"\"\"\n        <\/em>def get_num():\n            res = num_list[-1]\n            num_list.remove(res)\n            return res\n        num_list = [i for i in range(1, n * n + 1)]\n        res_list = [[get_num()]]\n        for i in range(2 * n - 2):\n            temp_list = []\n            # \u52a0\n            for j in range(len(res_list[0])):\n                temp_list.insert(0, get_num())\n            res_list.insert(0, temp_list)\n            if len(num_list) == 0:\n                return res_list\n            # \u7ffb\n            temp_iter = res_list.__iter__()\n            res_list = [i for i in zip(*temp_iter)]\n            # \u5012\n            for j in range(len(res_list)):\n                res_list[j] = res_list[j][::-1]\n        return res_list\nif __name__ == '__main__':\n    n = 1\n    print(Solution().generateMatrix(n))\n<\/pre>\n\n\n<p><strong>\u601d\u8def<\/strong>\uff1a0054\u7684\u9006\u8fc7\u7a0b\uff0c0054\u7684\u601d\u8def\u662f\u622a\u53d6\u3001\u5012\u8f6c\u3001\u7ffb\u8f6c\u3002\u56e0\u6b64\u5728\u8fd9\u91cc\u6211\u4eec\u5c31\u9700\u8981\u8fdb\u884c\u52a0\u3001\u7ffb\u8f6c\u3001\u5012\u8f6c\u3002<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"762\" height=\"194\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-56.png\" alt=\"\" class=\"wp-image-2976\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-56.png 762w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-56-300x76.png 300w\" sizes=\"(max-width: 762px) 100vw, 762px\" \/><\/figure><\/div>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/leetcode-cn.com\/problems\/spiral-matrix-ii\/ [&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":2236,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2975"}],"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=2975"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2975\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2975"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}