mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Update 48_旋转图像.md
This commit is contained in:
parent
34017d2c2f
commit
8346b2b1cb
|
@ -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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
Loading…
Reference in New Issue
Block a user