sundeepblue
4/30/2014 - 9:13 PM

rotate image clockwise for 90 digree

rotate image clockwise for 90 digree

void rotate_image(vector<vector<int>> &M) {
    int N = M.size();
    for(int i=0; i<N; i++) {
        for(int j=0; j<N-i; j++) {              // N-i
            swap(M[i][j], M[N-1+j][N-1+i]);
        }
    }
    for(int i=0; i<N/2; i++) {                  // N/2
        for(int j=0; j<N; j++) {
            swap(M[i][j], M[N-1-i][j]);
        }
    }
}