10. Rotate Image
30 Jun 2020 | Daily Algorithms
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)
}
};
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