From 039c8b1a0b855bea6acb3b398341a26a16c75dea Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Thu, 1 Sep 2022 01:01:22 +0200 Subject: [PATCH] =?UTF-8?q?problems(cpp):=20add=20=E2=80=9E48.=20Rotate=20?= =?UTF-8?q?Image=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- problems/rotate-image.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 problems/rotate-image.cpp diff --git a/problems/rotate-image.cpp b/problems/rotate-image.cpp new file mode 100644 index 0000000..324b6ff --- /dev/null +++ b/problems/rotate-image.cpp @@ -0,0 +1,18 @@ +#include +#include + +class Solution { +public: + void rotate(std::vector>& 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()); + } + } +};