rotate-image.dart (712B)
1 //Given a matrix rotate it clockwise 90 degrees 2 //To do this I created a temp matrix and using that updated 3 //the values in the original matrix rotated 90 degrees clockwise. 4 //The time complexity of this is O(n) where n is the number 5 //of values in the matrix. 6 //Time: 250ms Beats: 91.43% 7 //Memory: 142.4MB Beats: 68.57% 8 9 class Solution { 10 void rotate(List<List<int>> matrix) { 11 List<List<int>> temp_mat = []; 12 for(int i = 0 ; i < matrix.length ; ++i){ 13 temp_mat.add(List.from(matrix[i])); 14 } 15 for(int i = 0 ; i < temp_mat.length ; ++i){ 16 for(int x = 0 ; x < temp_mat[i].length ; ++x){ 17 matrix[x][matrix[x].length - 1 - i] = temp_mat[i][x]; 18 } 19 } 20 } 21 }