48. Rotate Image

48. Rotate Image

48. Rotate Image

/*

观察上面数据,需要做两步完成旋转

1. a[i][j] = a[j][i]

2. 然后对每行反序。 

 */

class Solution {
public:
    void rotate(vector<vector<int>>& matrix) {
        //transfor
        int n = matrix.size();
        for(int i = 0; i<n; i++)
        {
            for(int j = 0; j<=i;j++)
            {
                std::swap(matrix[i][j],matrix[j][i]);
            }
        }
        for (int i = 0; i<n;i++)
        {
            std::reverse(matrix[i].begin(),matrix[i].end());
        }
    }
};