标签:style blog http color os io ar for 2014
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
Follow up:
Could you do this in-place?
void rotate(vector<vector<int> > &matrix){ int n = matrix.size(); //沿副对角线翻转 for(int i = 0; i < n; ++i){ for(int j = 0; j < n - i; ++j){ int i2 = n - 1 - j, j2 = n - 1 - i; swap(matrix[i][j], matrix[i2][j2]); } } //沿水平中线翻转 for(int i = 0; i < n/2; ++i){ swap(matrix[i], matrix[n - i - 1]); } }
标签:style blog http color os io ar for 2014
原文地址:http://blog.csdn.net/zhengsenlie/article/details/38944545