LeetCode_832. Flipping an Image_Solution
一、题目描述

二、解题思路
题目所描述的意思是对每个数组先进行取反,并且对数组中的每个元素进行取反转换,所以一共要执行两个操作。
- 使用reverse函数解决水平翻转的操作;
- 由于是二进制矩阵,所以使X反转后的结果为 1-X。
三、Solution
C++代码:
class Solution {
public:
vector<vector<int>> flipAndInvertImage(vector<vector<int>>& A) {
size_t len = A.size(); //获得二进制数组的长度
for (int i = ; i < A.size(); i++)
{
reverse(A[i].begin(),A[i].end()); //执行翻转(逆序)二进制矩阵的操作
for (int j = ; j < A[i].size(); j++)
{
A[i][j] = - A[i][j]; //执行反转二进制矩阵的操作
}
}
return A;
}
};
四、个人收获
本题主要考察对数组和二进制的基本理解,同时也让我熟悉了reverse函数的用法。
五、参考资料
LeetCode_832. Flipping an Image_Solution的更多相关文章
- Flipping elements with WPF
http://yichuanshen.de/blog/2010/11/13/flipping-elements-with-wpf/ Have you already seen ForgottenTim ...
- Codeforces Gym 100803G Flipping Parentheses 线段树+二分
Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ...
- 【OpenMesh】Some basic operations: Flipping and collapsing edges
这一节中你将学到一些OpenMesh中早已提供的基础操作. 内容包括三角形网格边的翻转以及通过连接邻接的顶点边缘折叠. 三角形网格的翻转(Flipping edges) 考虑到两个邻接面的三角形网格中 ...
- Flipping Game(枚举)
Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #191 (Div. 2)---A. Flipping Game
Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Flipping Parentheses~Gym 100803G
Description A string consisting only of parentheses '(' and ')' is called balanced if it is one of t ...
- [LeetCode] Flipping an Image 翻转图像
Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resu ...
- [Swift]LeetCode832. 翻转图像 | Flipping an Image
Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resu ...
- Flipping an Image
Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resu ...
随机推荐
- 潭州课堂25班:Ph201805201 第十课 类的定义,属性和方法 (课堂笔记)
类的定义 共同属性,特征,方法者,可分为一类,并以名命之 class Abc: # class 定义类, 后面接类名 ( 规则 首字母大写 ) cls_name = '这个类的名字是Abc' # 在类 ...
- [NOI导刊2010提高]黑匣子
OJ题号:洛谷1801 思路:建立一个大根堆.一个小根堆.大根堆维护前i小的元素,小根堆维护当前剩下的元素. #include<cstdio> #include<queue> ...
- webstorm更改字体大小
webstorm是一款不错的开发软件,一起来看看webstorm怎么更改字体大小. 1,打开该软件后,点击上面菜单栏的“文件”/File,找到其子菜单中的“设置”/Setting,点击打开. 2,在新 ...
- Spark Client启动原理探索
经过几天闲暇时间的学习,终于又理解的深入了一些,关于Spark Client如何提交作业也更清晰了点. 在整体的流程图上是这样的: 大体的思路就是应用程序通过SparkSubmit提交程序后,自动在当 ...
- pycharm如何设置python版本、设置国内pip镜像、添加第三方类库
直接上图(mac环境): 一.设置项目的python版本 File->Default Settings ... 在弹出的界面上(参考下图),左上角的下拉框里,选择python解释器的版本即可(建 ...
- Java LinkedList工作原理及实现
1. 概述 以双向链表实现.链表无容量限制,但双向链表本身使用了更多空间,也需要额外的链表指针操作. 按下标访问元素—get(i)/set(i,e) 要悲剧的遍历链表将指针移动到位(如果i>数组 ...
- vim 正则替换功能
最近使用vim的正则替换功能,非常强大 一个文件: ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, 现在需要删除逗号前面的内容,那么在vim敲入命令: :%s/.*,//g 得到的结果是: ...
- Promise.then的第二个参数与catch的区别
1.异常捕获 getJSON("/post/1.json").then(function(post) { return getJSON(post.commentURL); }).t ...
- Oracle NID工具修改数据库DBID、数据库名称、数据库实例名
DBID是数据库的唯一标识符,在一些特殊场合会涉及到DBID的相关内容,本篇文章的目的是演示将DB_NAME的值从ORCL修改为ORCL1. 一.查看当前的环境 [oracle@oracledb ad ...
- swift3 与 OC 语法区别
1.Swift还增加了Objective-C中没有的类型比如元组(Tuple). 元组可以让你创建或者传递一组数据,比如作为函数的返回值时,你可以用一个元组可以返回多个值. 元组(tuples)把多个 ...