leetcode

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

0048.cpp (504B)


      1 class Solution {
      2     typedef vector<vector<int>> Mat;
      3     int n;
      4 
      5     void swap_group(Mat &matrix, int x, int y) {
      6         swap(matrix[x][y], matrix[y][n - x - 1]);
      7         swap(matrix[n - x - 1][n - y - 1], matrix[n - y - 1][x]);
      8         swap(matrix[x][y], matrix[n - x - 1][n - y - 1]);
      9     }
     10 
     11   public:
     12     void rotate(Mat &matrix) {
     13         n = matrix.size();
     14         for (int i = 0; i <= n / 2; i++)
     15             for (int j = i; j < n - i - 1; j++)
     16                 swap_group(matrix, i, j);
     17     }
     18 };