ROTATE MATRIX BY 90 [ARRAY QUESTION]-IMAGE ROTATE -48
Anonymous User
1516

we can rotate an array matrix by TRANSPOSING the given matrix and than rotating it.
step-1
transpose - changing row to column and column to row
step -2
rotate the matrix
"'
void rotate(vector<vector> &matrix){
int n = matrix.size();
for(int i = 0;i<n;i++){
swap(matrix[i][j],matrix[j][i]):
}
}
//reversing the row
for(int i = 0;i<n;i++){
reverse(matrix[i].begin(),matrix[i].end());
}
}

Comments (0)