题目:
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
class Solution(object):
def rotate(self, matrix):
"""
:type matrix: List[List[int]]
:rtype: void Do not return anything, modify matrix in-place instead.
"""
res = []
while matrix[0]:
tmp = []
for row in matrix:
tmp.insert(0,row.pop(0)) #list.insert(position,value)
res.append(tmp)
for i in range(len(matrix)): #这里,必须对matrix中的每行都进行修改,才能对其重新赋值,不能直接:matrix=res
matrix[i] = res[i]
s = Solution()
matrix = [[1,2],[3,4]]
s.rotate(matrix)
print matrix