Rotate a 2D matrix 90 degrees clockwise.
MediumProblem Statement
Rotate a 2D matrix 90 degrees clockwise.
Sample Input
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Sample Output
[7, 4, 1] [8, 5, 2] [9, 6, 3]
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
import java.util.*;
public class Main {
public static int[][] rotateMatrix() {
int[][] matrix = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
// Your code here
return matrix;
}
}
Input
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Expected Output
[7, 4, 1] [8, 5, 2] [9, 6, 3]