// Source : https://oj.leetcode.com/problems/rotate-image/ // Author : Hao Chen // Date : 2014-06-27 /********************************************************************************** * * 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? * **********************************************************************************/ #include #include #include #include using namespace std; void rotate(vector > &matrix) { int n = matrix.size(); for( int i=0; i > &matrix) { for(int i=0; i1){ n = atoi(argv[1]); } vector< vector > matrix; for (int i=1; i<=n; i++) { vector v; for(int j=1; j<=n; j++){ v.push_back( (i-1)*n + j ); } matrix.push_back(v); } printMatrix(matrix); rotate(matrix); printMatrix(matrix); return 0; }