Guest User

Untitled

a guest
Jun 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. class MyMatrix
  2. def self.rotate(matrix)
  3. orig_rows = matrix.size
  4. orig_cols = matrix[0].size
  5. # Note, read Array.new carefully - size references to the *same* obj
  6. rm = Array.new(orig_cols) { Array.new(orig_rows, 0) }
  7. matrix.each_with_index do |row, row_idx|
  8. new_row = orig_cols - 1
  9. row.each_with_index do |col, col_idx|
  10. new_col = row_idx
  11. rm[new_row][new_col] = col
  12. new_row -= 1
  13. end
  14. end
  15. return rm
  16. end
  17. end
Add Comment
Please, Sign In to add comment