Best answer! Less is more!


  • 0
    P
    public void rotate(int[][] matrix) {
        int rows = matrix.length, cols = matrix.length;
        for (int x = 0;x < rows/2;++x)
            for (int y = 0;y < cols - cols/2;++y) {
                int t = matrix[x][y];
                matrix[x][y] = matrix[rows-y-1][x];
                matrix[rows-y-1][x] = matrix[rows-x-1][cols-y-1];
                matrix[rows-x-1][cols-y-1] = matrix[y][cols-x-1];
                matrix[y][cols-x-1] = t;
            }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.