Um momento
Leetcode / 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;
            }
        }
    }
}
Gostou da aula? 😆👍
Apoie nosso trabalho com uma doação: