Skip to content

Commit 7308748

Browse files
committed
Ruby Solution for Rotate Image
1 parent eff3535 commit 7308748

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

ruby/0048-rotate-image.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
def rotate(matrix)
3+
l = 0
4+
r = matrix.size()-1
5+
6+
while l< r
7+
(0..(r-l-1)).each do |i|
8+
top = l
9+
bottom = r
10+
11+
top_left = matrix[top][l+i]
12+
13+
matrix[top][l+i] = matrix[bottom-i][l]
14+
15+
matrix[bottom-i][l] = matrix[bottom][r-i]
16+
17+
matrix[bottom][r-i] = matrix[top+i][r]
18+
19+
matrix[top+i][r] = top_left
20+
end
21+
22+
r -=1
23+
l +=1
24+
end
25+
end

0 commit comments

Comments
 (0)