48. Rotate Image
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
Follow-Up:
Could you do this in-place?
Solution:
class Solution(object):
def rotate(self, matrix):
"""
:type matrix: List[List[int]]
:rtype: void Do not return anything, modify matrix in-place instead.
"""
matrix.reverse()
for i in xrange(len(matrix)):
for j in xrange(i + 1, len(matrix[i])):
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]