Rotate a Rectangular Matrix Clockwise
Problem statement
Given a nonempty rectangular integer matrix with m rows and n columns, return its 90-degree clockwise rotation.
The returned matrix has n rows and m columns. Use only O(1) auxiliary space beyond the required output matrix.
Function
rotateRectangularMatrix(matrix: int[][]) → int[][]Examples
Example 1
matrix = [[1,2,3],[4,5,6]]return = [[4,1],[5,2],[6,3]]The two rows become the two columns read from bottom to top.
Example 2
matrix = [[1],[2],[3]]return = [[3,2,1]]A 3x1 column becomes a 1x3 row.
Example 3
matrix = [[7,8,9,10]]return = [[7],[8],[9],[10]]A 1x4 row becomes a 4x1 column.
Constraints
1 <= matrix.length, matrix[0].length <= 300.- Every row has the same length.
-1000000000 <= matrix[i][j] <= 1000000000.