leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0048.cpp (504B)
0 class Solution { 1 typedef vector<vector<int>> Mat; 2 int n; 3 4 void swap_group(Mat &matrix, int x, int y) { 5 swap(matrix[x][y], matrix[y][n - x - 1]); 6 swap(matrix[n - x - 1][n - y - 1], matrix[n - y - 1][x]); 7 swap(matrix[x][y], matrix[n - x - 1][n - y - 1]); 8 } 9 10 public: 11 void rotate(Mat &matrix) { 12 n = matrix.size(); 13 for (int i = 0; i <= n / 2; i++) 14 for (int j = i; j < n - i - 1; j++) 15 swap_group(matrix, i, j); 16 } 17 };