leetcode -- Rotate Image -- 要看有trick

https://leetcode.com/problems/rotate-image/

转置,再每行reverse即可
参考http://www.cnblogs.com/zuoyuan/p/3772978.html

class Solution(object):
    def rotate(self, matrix):
        """ :type matrix: List[List[int]] :rtype: void Do not return anything, modify matrix in-place instead. """
        n = len(matrix)
        for i in range(n):
            for j in range(i+1, n):
                matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
        for i in range(n):
            matrix[i].reverse()

你可能感兴趣的:(LeetCode)