题目大意

顺时针翻转数组(以图像存储为例)

解题思路

先镜像反转,再每行前后翻转

代码

class Solution(object):
    def rotate(self, matrix):
        """ :type matrix: List[List[int]] :rtype: void Do not return anything, modify matrix in-place instead. """
        for i in range(len(matrix)):  # 列长度
            for j in range(i+1, len(matrix)):  # 镜像反转
                matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
        for i in matrix:
            print i
        for i in range(len(matrix)):  # 前后翻转
            matrix[i].reverse()

总结

用到内置的reverse()了,算不算犯规呢