Turn the Matrix

A square matrix can be treated like a small image made of pixels. Given an n x n matrix matrix, rotate it 90 degrees clockwise. Return the rotated matrix.

Примеры

Ввод
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Вывод
[[7, 4, 1], [8, 5, 2], [9, 6, 3]]
Ввод
[[1, 2], [3, 4]]
Вывод
[[3, 1], [4, 2]]
Ввод
[[1]]
Вывод
[[1]]

Нужно реализовать

def rotate_image(matrix: list[list[int]]) -> list[list[int]]:

Теги

arraymath
PostgreSQLv16

Hier verschijnt het resultaat van je code

Visible tests
1
Input
[[1,2,3],[4,5,6],[7,8,9]]
Expected[[7,4,1],[8,5,2],[9,6,3]]
2
Input
[[1,2],[3,4]]
Expected[[3,1],[4,2]]
3
Input
[[1]]
Expected[[1]]
4
Input
[[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]
Expected[[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]
5
Input
[]
Expected[]
6
Input
[[7,8,9],[4,5,6],[1,2,3]]
Expected[[1,4,7],[2,5,8],[3,6,9]]
Focus radio
Paused · SomaFM · Fluid