Leetcode / 48. Rotate Image
Pick a programming language:
Here is the source code for the solution to this problem.
class Solution {
public void rotate(int[][] matrix) {
// reverse
int size = matrix.length;
for (int i = 0; i < size / 2; i++)
{
int[] temp = matrix[i];
matrix[i] = matrix[size - i - 1];
matrix[size - i - 1] = temp;
}
// finish rotation
for (int i = 0; i < size; i++)
{
for (int j = i + 1; j < size; j++)
{
int temp = matrix[i][j];
matrix[i][j] = matrix[j][i];
matrix[j][i] = temp;
}
}
}
}
Did you like the lesson? 😆👍
Consider a donation to support our work: