【Leetcode】Rotate Image

Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used.

Note:

All letters in hexadecimal (a-f) must be in lowercase.

The hexadecimal string must not contain extra leading 0s. If the number is zero, it is represented by a single zero character '0'; otherwise, the first character in the hexadecimal string will not be the zero character.

The given number is guaranteed to fit within the range of a 32-bit signed integer.

You must not use any method provided by the library which converts/formats the number to hex directly.

class Solution(object):

    def rotate(self, matrix):

        """

        :type matrix: List[List[int]]

        :rtype: void Do not return anything, modify matrix in-place instead.

        """

        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]

1 第0行变成第n-1列,第1行变成第n-2列,第n-1行变成0列

2 重要的是题目要求是in-place的,所以必须所有的同时替换才行,不然就会出现错误

3 先对矩阵进行reverse,之后再交换值,就是in-place的了

4  for j in range(i):注意这range是到i

你可能感兴趣的:(【Leetcode】Rotate Image)