{"id":2176,"date":"2016-09-10T09:26:14","date_gmt":"2016-09-10T01:26:14","guid":{"rendered":"http:\/\/boweihe.me\/?p=2176"},"modified":"2016-09-10T09:26:14","modified_gmt":"2016-09-10T01:26:14","slug":"48-rotate-image","status":"publish","type":"post","link":"https:\/\/dayandcarrot.space\/?p=2176","title":{"rendered":"48. Rotate Image"},"content":{"rendered":"<h3>\u601d\u8def<\/h3>\n<p>\u5265\u6d0b\u8471\u4e00\u6837\u7684\u8fc7\u7a0b\u53ef\u4ee5\u5b9e\u73b0\u539f\u4f4d\u66ff\u6362\uff0c\u53ea\u8981\u4e00\u4e2a\u6700\u5927\u4e3an\u7684\u6682\u5b58\u6570\u7ec4\u5c31\u884c\u4e86\u3002<\/p>\n<pre class=\"lang:default decode:true \">0, 1, 2, 3\n4, 5, 6, 7\n8, 9, A, B\nC, D, E, F<\/pre>\n<p>\u8fd9\u4e48\u4e2a\u77e9\u9635\uff0c\u9996\u5148\u4ece\u6700\u5916\u9762\u4e00\u5708\u5265\u8d77\uff0c\u5c06[0,1,2]\u8bb0\u5f55\u4e0b\u6765\uff0c\u7136\u540e\u66ff\u6362\u4e3a[C,8,4]\uff1b\u7136\u540e\u987a\u65f6\u9488\u7ee7\u7eed\uff0c\u5c06[3,7,B]\u8bb0\u5f55\u4e0b\u6765\uff0c\u7136\u540e\u7528\u521a\u624d\u8bb0\u4f4f\u7684[0,1,2]\u66ff\u6362&#8230;<\/p>\n<h3>\u4ee3\u7801<\/h3>\n<pre class=\"lang:c++ decode:true \">class Solution {\npublic:\n    void rotate(vector&lt;vector&lt;int&gt;&gt;&amp; matrix) {\n        int floor = 0;\n        int ceiling = matrix.size() - 1;\n        if(ceiling &lt; 0)\n            return; \/\/empty\n        vector&lt;int&gt; temp;\n        while(floor &lt; ceiling){\n            \/\/up\n            for(int col=floor; col&lt;ceiling; col++){\n                temp.push_back(matrix[floor][col]); \/\/remember current\n                matrix[floor][col] = matrix[ceiling-(col-floor)][floor]; \/\/replace with left column values\n            }\n            \/\/right\n            for(int row=floor; row&lt;ceiling; row++){\n                temp.push_back(matrix[row][ceiling]);  \/\/remember current\n                matrix[row][ceiling] = temp[0]; \/\/replace\n                temp.erase(temp.begin());\n            }\n            \/\/bottom\n            for(int col=ceiling; col&gt;floor; col--){\n                temp.push_back(matrix[ceiling][col]);\n                matrix[ceiling][col] = temp[0];\n                temp.erase(temp.begin());\n            }\n            \/\/left\n            for(int row=ceiling; row&gt;floor; row--){\n                matrix[row][floor] = temp[0];\n                temp.erase(temp.begin());\n            }\n            floor++;\n            ceiling--;\n        }\n    }\n};<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u601d\u8def \u5265\u6d0b\u8471\u4e00\u6837\u7684\u8fc7\u7a0b\u53ef\u4ee5\u5b9e\u73b0\u539f\u4f4d\u66ff\u6362\uff0c\u53ea\u8981\u4e00\u4e2a\u6700\u5927\u4e3an\u7684\u6682\u5b58\u6570\u7ec4\u5c31\u884c\u4e86\u3002 0, 1, 2, 3 4, 5, 6, 7 8, 9, A, B C, D, E, F \u8fd9\u4e48\u4e2a\u77e9\u9635\uff0c\u9996\u5148\u4ece\u6700\u5916\u9762\u4e00\u5708\u5265\u8d77\uff0c\u5c06[0,1,2]\u8bb0\u5f55\u4e0b\u6765\uff0c\u7136\u540e\u66ff\u6362\u4e3a[C,8,4]\uff1b\u7136\u540e\u987a\u65f6\u9488\u7ee7\u7eed\uff0c\u5c06[3,7,B]\u8bb0\u5f55\u4e0b\u6765\uff0c\u7136\u540e\u7528\u521a\u624d\u8bb0\u4f4f\u7684[0,1,2]\u66ff\u6362&#8230; \u4ee3\u7801 class Solution { public: void rotate(vector&lt;vector&lt;int&gt;&gt;&amp; matrix) { int floor = 0; int ceiling = matrix.size() &#8211; 1; if(ceiling &lt; 0) return; \/\/empty vector&lt;int&gt; temp; while(floor &lt; ceiling){ \/\/up for(int col=floor; col&lt;ceiling; col++){ temp.push_back(matrix[floor][col]); \/\/remember [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[66],"class_list":["post-2176","post","type-post","status-publish","format-standard","hentry","category-study","tag-leetcode-oj"],"_links":{"self":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/2176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2176"}],"version-history":[{"count":0,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/2176\/revisions"}],"wp:attachment":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}