From 7308748c4d450ecd5ed300a47e27dcd6a6aed492 Mon Sep 17 00:00:00 2001 From: saip7795 Date: Sun, 8 Jan 2023 16:21:32 -0500 Subject: [PATCH] Ruby Solution for Rotate Image --- ruby/0048-rotate-image.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 ruby/0048-rotate-image.rb diff --git a/ruby/0048-rotate-image.rb b/ruby/0048-rotate-image.rb new file mode 100644 index 000000000..6e260d4af --- /dev/null +++ b/ruby/0048-rotate-image.rb @@ -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 \ No newline at end of file