mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
problems(cpp): add „48. Rotate Image“
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
71b16b3ab8
commit
039c8b1a0b
1 changed files with 18 additions and 0 deletions
18
problems/rotate-image.cpp
Normal file
18
problems/rotate-image.cpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
void rotate(std::vector<std::vector<int>>& matrix)
|
||||
{
|
||||
for (std::size_t i = 0; i < matrix.size(); i++) {
|
||||
for (std::size_t j = i; j < matrix.size(); j++) {
|
||||
std::swap(matrix[i][j], matrix[j][i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& row : matrix) {
|
||||
std::reverse(row.begin(), row.end());
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue