Update 48_旋转图像.md

pull/46/head
JZFamily 2018-06-24 19:27:21 +08:00 committed by GitHub
parent 34017d2c2f
commit 8346b2b1cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 0 deletions

View File

@ -125,3 +125,35 @@ public:
}
};
```
### puck
class Solution
{
public:
void rotate(vector<vector<int>> &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]);
}
}
}
};
```