We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent eff3535 commit 7308748Copy full SHA for 7308748
ruby/0048-rotate-image.rb
@@ -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
25
+end
0 commit comments