标签:
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?
Array
#include<iostream> #include<algorithm> #include<vector> using namespace std; void rotate(vector<vector<int>>& matrix) { int n=matrix.size(); for(int i=0;i<n;i++) for(int j=i;j<n;j++) {int temp;temp=matrix[j][i];matrix[j][i]=matrix[i][j];matrix[i][j]=temp;} for(int i=0;i<n;i++) reverse(matrix[i].begin(),matrix[i].end()); } int main() { }
leetcode_48题——Rotate Image(矩阵计算)
标签:
原文地址:http://www.cnblogs.com/yanliang12138/p/4543294.html