leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit c55e4f0dee76504429d5eed88abe6eab704e719a
parent b668d4085e3d5a39c1287f58ffb1b93acb2372c7
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Sat, 20 May 2023 19:23:54 -0500

Completed rotate image using dart

Diffstat:
Arotate-image/rotate-image.dart | 21+++++++++++++++++++++
1 file changed, 21 insertions(+), 0 deletions(-)

diff --git a/rotate-image/rotate-image.dart b/rotate-image/rotate-image.dart @@ -0,0 +1,21 @@ +//Given a matrix rotate it clockwise 90 degrees +//To do this I created a temp matrix and using that updated +//the values in the original matrix rotated 90 degrees clockwise. +//The time complexity of this is O(n) where n is the number +//of values in the matrix. +//Time: 250ms Beats: 91.43% +//Memory: 142.4MB Beats: 68.57% + +class Solution { + void rotate(List<List<int>> matrix) { + List<List<int>> temp_mat = []; + for(int i = 0 ; i < matrix.length ; ++i){ + temp_mat.add(List.from(matrix[i])); + } + for(int i = 0 ; i < temp_mat.length ; ++i){ + for(int x = 0 ; x < temp_mat[i].length ; ++x){ + matrix[x][matrix[x].length - 1 - i] = temp_mat[i][x]; + } + } + } +}