[LeetCode&Python] Problem 832. Flipping an Image
Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resulting image.
To flip an image horizontally means that each row of the image is reversed. For example, flipping [1, 1, 0] horizontally results in [0, 1, 1].
To invert an image means that each 0 is replaced by 1, and each 1 is replaced by 0. For example, inverting [0, 1, 1] results in [1, 0, 0].
Example 1:
Input: [[1,1,0],[1,0,1],[0,0,0]]
Output: [[1,0,0],[0,1,0],[1,1,1]]
Explanation: First reverse each row: [[0,1,1],[1,0,1],[0,0,0]].
Then, invert the image: [[1,0,0],[0,1,0],[1,1,1]]
Example 2:
Input: [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]
Output: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
Explanation: First reverse each row: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]].
Then invert the image: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
Notes:
1 <= A.length = A[0].length <= 200 <= A[i][j] <= 1
class Solution:
def flipAndInvertImage(self, A):
"""
:type A: List[List[int]]
:rtype: List[List[int]]
""" for rowIndex in range(len(A)):
A[rowIndex]=[(i^1) for i in A[rowIndex][::-1]] return A
[LeetCode&Python] Problem 832. Flipping an Image的更多相关文章
- [LeetCode&Python] Problem 108. Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Fo ...
- [LeetCode&Python] Problem 387. First Unique Character in a String
Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...
- [LeetCode&Python] Problem 427. Construct Quad Tree
We want to use quad trees to store an N x N boolean grid. Each cell in the grid can only be true or ...
- [LeetCode&Python] Problem 371. Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...
- [LeetCode&Python] Problem 520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not. We define the u ...
- [LeetCode&Python] Problem 226. Invert Binary Tree
Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: 4 / \ 7 2 / \ / \ 9 6 3 1 Tr ...
- [LeetCode&Python] Problem 905: Sort Array By Parity
Given an array A of non-negative integers, return an array consisting of all the even elements of A, ...
- [LeetCode&Python] Problem 1: Two Sum
Problem Description: Given an array of integers, return indices of the two numbers such that they ad ...
- [LeetCode&Python] Problem 682. Baseball Game
You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 ...
随机推荐
- 使用 rlist 包处理嵌套数据结构
在前面的章节中,我们已经学习了存储表的关系型数据库,支持嵌套数据结构的非关系型数据库.在 R 中,最常见的嵌套数据结构就是列表对象.之前的章节都关注操作表格数据.本节,我们一起玩转作者开发的 rlis ...
- 《F4+2团队项目需求改进与系统设计》
任务一 a.分析<动态的太阳系模型项目需求规格说明书>初稿的不足. 任务概述描述的有些不具体,功能的规定不详细,在此次作业进行了修改. b.参考<构建之法>8.5节功能的定位和 ...
- 《剑指offer》第二十三题(链表中环的入口结点)
// 面试题23:链表中环的入口结点 // 题目:一个链表中包含环,如何找出环的入口结点?例如,在图3.8的链表中, // 环的入口结点是结点3. #include <iostream> ...
- 《剑指offer》第十七题(打印1到最大的n位数)
// 面试题17:打印1到最大的n位数 // 题目:输入数字n,按顺序打印出从1最大的n位十进制数.比如输入3,则 // 打印出1.2.3一直到最大的3位数即999. #include <ios ...
- 【Golang】解决Go test执行单个测试文件提示未定义问题
背景 很多人记录过怎么执行Go test单个文件或者单个函数,但是要么对执行单文件用例存在函数或变量引用的场景避而不谈,要么提示调用了其它文件中的模块会报错.其实了解了go test命令的机制之后,这 ...
- (GoRails) 自动侦测用户的时区,使用javascript 的jszt库。
传统方法见:http://www.cnblogs.com/chentianwei/p/9369904.html ⚠️: 两个方法最后都要有controller中的类似before_action :se ...
- CF-500div2-A/B/C
A. Piles With Stones time limit per test 1 second memory limit per test 256 megabytes input standard ...
- struts2整合axis2后,访问不到wsdl,被struts2拦截的解决办法
在struts2中整合axis2后,访问wsdl的时候显示404 not found There is no Action mapped for action name xxxxxxxx. 解决办法 ...
- pos提交提交数据时碰到Django csrf
我的github(PS:希望star):https://github.com/thWinterSun/v-admin 最近在用Vue写前端代码,再用vue-resource向后台提交数据.项目后台是用 ...
- React-Router v4.0 hashRouter使用js跳转
React-Router v4.0上已经不推荐使用hashRouter,主推browserRouter,但是因为使用browserRouter需要服务端配合可能造成不便,有时还是需要用到hashRou ...