Rotate Matrix
Given an n x n matrix, where each of the elements in the matrix is an integer, rotate the matrix by 90 degrees clockwise. You must rotate the matrix in-place, which means you modify the original matrix directly without using any additional data structures.
[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]
Explanation. The matrix is rotated 90 degrees clockwise. The rows become columns and the order of columns is reversed.
[ [ 5, 1 ], [ 2, 3 ] ]
Explanation. For a 2x2 matrix, the rotation leads the elements to switch places according to their symmetric positions about the center.
Follow-up: Could you implement a solution that minimizes the number of write operations?
1. The matrix will contain at least one element.\n2. `n` will be >= 1, where `n` is both the width and height of the matrix.
- Views
- 2