832. Flipping an Image
Approach 1: Using map
def flipAndInvertImage(self, A):
"""
:type A: List[List[int]]
:rtype: List[List[int]]
"""
def invert(i):
return 0 if i == 1 else 1
def flip(l):
return list(map(invert, l))[::-1]
return map(flip, A)Approach 2: Using lambda instead of the map
def flipAndInvertImage(self, A):
"""
:type A: List[List[int]]
:rtype: List[List[int]]
"""
def flip(l):
return list(map(lambda i: 0 if i == 1 else 1, l))[::-1]
return map(flip, A)Approach 3: Improved invert
Last updated