for Robot Artificial Inteligence

10. Rotate Image

|

class Solution {
public:
    void rotate(vector<vector<int>>& matrix) {
        int n = matrix.size();// 3 x 3
        for(int i = 0; i<n; ++i)
        {
            for(int j=0; j<n;++j)
            {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = temp
            }
        } // transpose
        for(int i = 0; i<n; ++i)
        {
            for(int j=0; j<(n/2);++j)
            {
                int temp = marix[i][j];
                matrix[i][j] = matrix[i][n-j-1];
                matrix[i][n-j-1] = temp;
            }
        } // flip the matrix horizontally, Fixed 2 colum and change like(1,3)(4,6)(7,9)
    }
};

Comments