Rotate Image
easy
1. You are given an n x n 2D matrix representing an image. 2. rotate the image by 90 degrees (clockwise). 3. You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. 4. DO NOT allocate another 2D matrix and do the rotation.
Constraints
1. matrix.length == n 2. matrix[i].length == n 3. 1 <= n <= 20 4. -1000 <= matrix[i][j] <= 1000
Format
Input
matrix = { {11, 12, 13, 14}, {21, 22, 23, 24}, {31, 32, 33, 34}, {41, 42, 43, 44} }
Output
matrix = { {41, 31, 21, 11}, {42, 32, 22, 12}, {43, 33, 23, 13}, {44, 34, 24, 14} }
Example
Sample Input
3
11 12 13
21 22 23
31 32 33
Sample Output
31 21 11
32 22 12
33 23 13