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]); + } + } + } +}; +```