Created
April 4, 2024 03:55
-
-
Save codertcet111/a1c60c95687746caa7b98a932ec49c2d to your computer and use it in GitHub Desktop.
Leetcode 48 Rotate image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Leetcode 48 Rotate image | |
# @param {Integer[][]} matrix | |
# @return {Void} Do not return anything, modify matrix in-place instead. | |
def rotate(matrix) | |
# Just change row's to column, like [1,2,3] 1st row will become last column | |
# Then 2nd row [4,5,6] will become 2nd column and so on | |
#ignore: matrix.transpose.reverse | |
n = matrix.length | |
(0...n).each do |i| | |
(0..i).each do |j| | |
temp = matrix[i][j] | |
matrix[i][j] = matrix[j][i] | |
matrix[j][i] = temp | |
end | |
end | |
matrix.each(&:reverse!) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment