Skip to content

Instantly share code, notes, and snippets.

@codertcet111
Created April 4, 2024 03:55
Show Gist options
  • Save codertcet111/a1c60c95687746caa7b98a932ec49c2d to your computer and use it in GitHub Desktop.
Save codertcet111/a1c60c95687746caa7b98a932ec49c2d to your computer and use it in GitHub Desktop.
Leetcode 48 Rotate image
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