Java rotation 192ms


  • 0
    K
    public class Solution {
        public void rotate(int[][] matrix) {
            
            int y = matrix.length -1;
            int x = matrix[0].length-1;
            
            // rotated temp array 
            int[][] rot = new int[ x+1][y+1];
            
            for(int i =0 ; i <= y; i++){
                for (int j = 0; j <= x; j++)
                {
                    rot[i][j] = matrix[y-j][i];
                }
            }
            for(int i = 0; i < rot.length; i++)
                matrix[i] = rot[i].clone();
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.