Leetcode 832. Flipping an Image

python列表切片有~这种简单表示.

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

 

posted @ 2019-04-09 06:20  周洋  阅读(146)  评论(0编辑  收藏  举报