← 返回 apple 的题目列表Rotate a 2D Array by 90 Degrees
类型:online_judge
Given a n x n 2D array matrix, write an algorithm to rotate the matrix 90 degrees clockwise. You must rotate the matrix in-place, which means you have to modify the input array directly, and use O(1) extra space.
Input:
Matrix matrix of size n x n.
Output:
The matrix after being rotated 90 degrees clockwise.
Example:
Input:
[
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
Output:
[
[7, 4, 1],
[8, 5, 2],
[9, 6, 3]
]
Constraints:
n >= 1, n <= 20.
Example
Input
[[1,2,3],[4,5,6],[7,8,9]]