Leetcode 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?

倒置数组后,交换x,y的下标。

class Solution(object):
    def rotate(self, matrix):
        matrix.reverse()
        for i in range(len(matrix)):
            for j in range(i):
                matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]

 

posted @ 2016-05-13 13:53  lilixu  阅读(94)  评论(0编辑  收藏  举报