Rotate Image

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?

class Solution {
public:
    void rotate(vector<vector<int> > &matrix) {
        int n=matrix.size();
        vector<vector<int>> newm;
        vector<int> v;
        for(int i=0;i<n;i++)
        {
            v.clear();
            for(int j=0;j<n;j++)
                v.push_back(matrix[n-j-1][i]);
            newm.push_back(v);
        }
        matrix= newm;
    }
}; 
posted @ 2014-05-29 16:17  erictanghu  阅读(128)  评论(0编辑  收藏  举报