[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 };
复制代码

 

posted @   jianchao-li  阅读(145)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示