Skip to content
LC-0832 Easy LeetCode

832. Flipping an Image

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 83% Topics: Array, Two Pointers, Bit Manipulation, Matrix, Simulation
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n^2)
# Space: O(1)


class Solution(object):
    def flipAndInvertImage(self, A):
        """
        :type A: List[List[int]]
        :rtype: List[List[int]]
        """
        for row in A:
            for i in xrange((len(row)+1) // 2):
                row[i], row[~i] = row[~i] ^ 1, row[i] ^ 1
        return A

Solution from kamyu104/LeetCode-Solutions · MIT