Created
November 21, 2019 03:00
-
-
Save eebasadre20/cb74ba987d65c1e4d1bf48b72fe099fc to your computer and use it in GitHub Desktop.
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
# @param {Integer[][]} matrix | |
# @return {Void} Do not return anything, modify matrix in-place instead. | |
def rotate(matrix) | |
matrix_length = matrix.length | |
x = 0 | |
y = 0 | |
while x < matrix_length | |
y = x | |
while y < matrix_length | |
temp = matrix[x][y] | |
matrix[x][y] = matrix[y][x] # 0 - 0, 0,1 - 1,0 | |
matrix[y][x] = temp | |
y += 1 | |
end | |
x += 1 | |
end | |
x = 0 | |
while x < matrix_length | |
y = 0 | |
while y < (matrix_length / 2) | |
temp = matrix[x][y] | |
matrix[x][y] = matrix[x][matrix_length - 1 - y] # 0,0 - 0,2, 1,0 - 1,2 | |
matrix[x][matrix_length - 1 - y] = temp | |
y += 1 # 0, 1 | |
end | |
x += 1 | |
end | |
matrix | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment