Rotate Image

来源:互联网 发布:python datetime 微秒 编辑:程序博客网 时间:2024/05/16 01:08

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<iostream>#include<vector>#include<algorithm>using namespace std;//先求转置.void rotate(vector<vector<int> > &matrix) {for (int i = 0; i != matrix.size();++i){for (int j = i+1; j != matrix[0].size();++j){swap(matrix[i][j], matrix[j][i]);}reverse(matrix[i].begin(), matrix[i].end());}}


 

0 0