← 返回 amazon 的题目列表Rotate Square Matrix by 90 Degrees
类型:online_judge
Problem: Rotate an N×N Matrix Clockwise by 90 Degrees
Given a non-empty N × N 2D matrix matrix (a square matrix), rotate the matrix in-place by 90 degrees clockwise.
I/O
Input: integer N, followed by an N × N matrix.
Output: the rotated matrix in the same format.
Constraints
1 <= N <= 500
matrix[i][j] fits in 32-bit signed integer
Must be in-place with extra space as close to O(1) as possible.
Example
Input:
3
1 2 3
4 5 6
7 8 9
Output:
7 4 1
8 5 2
9 6 3
Example
Input
1
5
Output
5