LeetCode-832翻转图像

LeetCode-832翻转图像_第1张图片

我的代码:
class Solution:
    def flipAndInvertImage(self, A):
        """
        :type A: List[List[int]]
        :rtype: List[List[int]]
        """
        self.A = A
        list_reverses = []
        for i in range(0,len(self.A)):
            list_reverse=list(reversed(self.A[i]))
            list_reverses.append(list_reverse)
            for j in range(0,len(list_reverses[i])):
                if list_reverses[i][j]==1:
                    list_reverses[i][j] =0
                elif list_reverses[i][j]==0:
                    list_reverses[i][j] =1
        return list_reverses
            
其他优秀代码:
class Solution:
    def flipAndInvertImage(self, A):
        """
        :type A: List[List[int]]
        :rtype: List[List[int]]
        """
        for i in range(len(A)):
            A[i] = A[i][::-1]
            for j in range(len(A[i])):
                A[i][j] = A[i][j]^1
        return A
^:按位异或运算符:当两对应的二进位相异时,结果为1



你可能感兴趣的:(Python,Leetcode)