给定一个N×N的二维矩阵表示图像,90度顺时针旋转图像。
样例
给出一个矩形[[1,2],[3,4]],90度顺时针旋转后,返回[[3,1],[4,2]]
在原地完成
class Solution { public: /** * @param matrix: A list of lists of integers * @return: Void */ void rotate(vector<vector<int> > &matrix) { // write your code here int rows=matrix.size(); if(rows==0) return; int cols=matrix[0].size(); if(cols==0) return; int low=0; int high=rows-1; while(low<high){ swap(matrix[low++],matrix[high--]); } for(int i=0;i<rows;i++){ for(int j=i;j<cols;j++){ swap(matrix[i][j],matrix[j][i]); } } return; } };