leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit f3112ac70d2216bb1091ebb4fb3634a87a1efda2
parent eab73660e5f82bd021bac7afac5287c62827e0ec
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Mon,  6 Feb 2023 16:49:45 +0100

Data Structure II: Day 3

Diffstat:
AProblems/0048.cpp | 17+++++++++++++++++
MREADME.md | 1+
2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/Problems/0048.cpp b/Problems/0048.cpp @@ -0,0 +1,17 @@ +class Solution { + typedef vector<vector<int>> Mat; + int n; + + void swap_group(Mat &matrix, int x, int y) { + swap(matrix[x][y], matrix[y][n - x - 1]); + swap(matrix[n - x - 1][n - y - 1], matrix[n - y - 1][x]); + swap(matrix[x][y], matrix[n - x - 1][n - y - 1]); + } + +public: + void rotate(Mat &matrix) { + n = matrix.size(); + for (int i = 0; i <= n / 2; i++) + for (int j = i; j < n - i - 1; j++) swap_group(matrix, i, j); + } +}; diff --git a/README.md b/README.md @@ -51,6 +51,7 @@ for solving problems. | 0043 | Medium | [Multiply Strings](Problems/0043.cpp) | | 0045 | Medium | [Jump Game II](Problems/0045.cpp) | | 0046 | Medium | [Permutations](Problems/0046.cpp) | +| 0048 | Medium | [Rotate Image](Problems/0048.cpp) | | 0049 | Medium | [Group Anagrams](Problems/0049.cpp) | | 0053 | Medium | [Maximum Subarray](Problems/0053.cpp) | | 0054 | Medium | [Spiral Matrix](Problems/0054.cpp) |