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

 

相关文章:

  • 2021-09-21
  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2022-02-27
  • 2022-12-23
  • 2022-02-12
  • 2021-10-27
猜你喜欢
  • 2021-08-26
  • 2021-07-24
  • 2021-09-19
  • 2021-10-22
  • 2021-12-06
相关资源
相似解决方案