[LeetCode] Rotate Image

A simple and in-place idea: first reverse the image in row-major order and then transpose it :-)

 1 class Solution {
 2 public:
 3     void rotate(vector<vector<int>>& matrix) {
 4         reverse(begin(matrix), end(matrix));
 5         int m = matrix.size(), n = matrix[0].size();
 6         for (int i = 0; i < m; i++)
 7             for (int j = 0; j < i; j++)
 8                 swap(matrix[i][j], matrix[j][i]);
 9     }
10 };
原文地址:https://www.cnblogs.com/jcliBlogger/p/4717793.html