标签:ons image def bsp sel 优秀代码 ima 自己的 flip
class Solution(object): def flipAndInvertImage(self, A): """ :type A: List[List[int]] :rtype: List[List[int]] """ B=[] row=len(A) col=len(A[0]) for i in range(row): B.append(A[i][::-1]) for j in range(col): B[i][j]^=1 return B
Runtime: 52 ms, faster than 97.21% of Python online submissions forFlipping an Image.
class Solution: def flipAndInvertImage(self, A): """ :type A: List[List[int]] :rtype: List[List[int]] """ rows = len(A) cols = len(A[0]) for row in range(rows): A[row] = A[row][::-1] for col in range(cols): A[row][col] ^= 1 return A
1.0和1取反,可以使用异或1
2.可以直接对原来的list进行操作,省的重新定义list
标签:ons image def bsp sel 优秀代码 ima 自己的 flip
原文地址:https://www.cnblogs.com/captain-dl/p/10264346.html