From 8346b2b1cb8874a4bb8dbb67c01d05ba3d681cec Mon Sep 17 00:00:00 2001 From: JZFamily Date: Sun, 24 Jun 2018 19:27:21 +0800 Subject: [PATCH] =?UTF-8?q?Update=2048=5F=E6=97=8B=E8=BD=AC=E5=9B=BE?= =?UTF-8?q?=E5=83=8F.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LeetCode-CN/48_旋转图像.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/LeetCode-CN/48_旋转图像.md b/LeetCode-CN/48_旋转图像.md index 0543f62..c24c592 100644 --- a/LeetCode-CN/48_旋转图像.md +++ b/LeetCode-CN/48_旋转图像.md @@ -125,3 +125,35 @@ public: } }; ``` +### puck +class Solution +{ + public: + void rotate(vector> &matrix) + { + auto n = matrix.size(); + auto max = n - 1; + auto half = n / 2; + + for (int i{}; i < half; ++i) + { + for (int j{}; j < half; ++j) + { + std::swap(matrix[i][j], matrix[j][max - i]); + std::swap(matrix[i][j], matrix[max - i][max - j]); + std::swap(matrix[i][j], matrix[max - j][i]); + } + } + + if (n == 2 * half + 1) + { + for (int i{}; i < half; ++i) + { + std::swap(matrix[i][half], matrix[half][max - i]); + std::swap(matrix[i][half], matrix[max - i][half]); + std::swap(matrix[i][half], matrix[half][i]); + } + } + } +}; +```