Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyMatrix
- def self.rotate(matrix)
- orig_rows = matrix.size
- orig_cols = matrix[0].size
- # Note, read Array.new carefully - size references to the *same* obj
- rm = Array.new(orig_cols) { Array.new(orig_rows, 0) }
- matrix.each_with_index do |row, row_idx|
- new_row = orig_cols - 1
- row.each_with_index do |col, col_idx|
- new_col = row_idx
- rm[new_row][new_col] = col
- new_row -= 1
- end
- end
- return rm
- end
- end
Add Comment
Please, Sign In to add comment