← 返回 apple 的题目列表Rotate a Matrix by 90 Degrees In Place
类型:online_judge
Problem: Rotate a Matrix 90 Degrees Clockwise In Place
Given a 2D matrix matrix, rotate it 90 degrees clockwise.
Requirements:
You must modify the matrix in place (use only O(1) extra space).
The matrix is an N x N square matrix.
Input Format
The first line contains an integer N, the size of the matrix.
The next N lines each contain N integers describing the matrix.
Output Format
Print the rotated matrix as N lines, each with N integers separated by spaces.
Constraints
1 <= N <= 200
Elements fit in 32-bit signed integers.
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