Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1969 from saip7795/sp/rotate_image
Browse files Browse the repository at this point in the history
Create: 0048-Rotate-Image.rb
  • Loading branch information
tahsintunan authored Jan 13, 2023
2 parents aea1bb3 + 7308748 commit fd9d1f4
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions ruby/0048-rotate-image.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

def rotate(matrix)
l = 0
r = matrix.size()-1

while l< r
(0..(r-l-1)).each do |i|
top = l
bottom = r

top_left = matrix[top][l+i]

matrix[top][l+i] = matrix[bottom-i][l]

matrix[bottom-i][l] = matrix[bottom][r-i]

matrix[bottom][r-i] = matrix[top+i][r]

matrix[top+i][r] = top_left
end

r -=1
l +=1
end
end

0 comments on commit fd9d1f4

Please sign in to comment.