LeetCode 832 Flipping an Image

LeetCode 832 Flipping an Image Problem

Download Code
class Solution(object):
    def flipAndInvertImage(self, A):
        for row in A:
            for i in xrange((len(row) + 1) / 2):
                """
                In Python, the shortcut row[~i] = row[-i-1] = row[len(row) - 1 - i]
                helps us find the i-th value of the row, counting from the right.
                """
                row[i], row[~i] = row[~i] ^ 1, row[i] ^ 1
        return A
        # return [[1 ^ i for i in row[::-1]] for row in A]
Download Flipping an Image.py

List of all Flipping an Image problems

Leetcode 832 Flipping an Image problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.

Feedback is the most important part of any website.

If you have any query, suggestion or feedback, Please feel free to contact us.