class Solution:
def flipAndInvertImage(self, A: List[List[int]]) -> List[List[int]]:
for a in A:
first = 0
last = len(a)-1
while first<last:
a[first],a[last]=1-a[last],1-a[first]
first += 1
last -= 1
if len(a)&1 is 1:
index = int((len(a)-1)/2)
a[index] = 1-a[index]
return A
48ms,13.1M
优化一:
class Solution:
def flipAndInvertImage(self, A: List[List[int]]) -> List[List[int]]:
return [[1-row[i] for i in range(len(row)-1,-1,-1)] for row in A]
48ms,13.2M