LeetCode/problems/rotate-image.cpp
Matej Focko 039c8b1a0b
problems(cpp): add „48. Rotate Image“
Signed-off-by: Matej Focko <mfocko@redhat.com>
2022-09-01 01:01:22 +02:00

18 lines
430 B
C++

#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());
}
}
};