python写算法题:leetcode: 48. Rotate Image

class Solution(object):
    def rotate(self, matrix):
        """
        :type matrix: List[List[int]]
        :rtype: None Do not return anything, modify matrix in-place instead.
        """
        n=len(matrix)
        for i in xrange(n/2,n):
            if i*2==n-1: continue
            for j in xrange(n/2,n):
                #print "({},{})=>({},{})=>({},{})=>({},{})".format(
                #    i, j, j, n-1-i,  n-1-i, n-j-1, n-j-1, i)
                matrix[j][n-1-i],matrix[n-1-i][n-j-1],matrix[n-j-1][i],matrix[i][j]=\
                matrix[i][j],matrix[j][n-1-i],matrix[n-1-i][n-j-1],matrix[n-j-1][i]
        

 

点赞