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 ...
随机推荐
- cf348D. Turtles(LGV定理 dp)
题意 题目链接 在\(n \times m\)有坏点的矩形中找出两条从起点到终点的不相交路径的方案数 Sol Lindström–Gessel–Viennot lemma的裸题? 这个定理是说点集\( ...
- CODEVS.3990.中国余数定理2(CRT)
题目链接 颓了一天 写个模板吧.. Chinese_Remainder_Theorem: MashiroSky.远航之曲 #include <cstdio> #include <cc ...
- GitHub Desktop的简单使用
- dataGridView使用指南系列一、回车换行或换列完美解决方案
在使用datagridview控件时,默认按回车是跳转到下一行的当前列的,要想让按回车跳转到同一行的下一列该怎么做呢? 百度搜索了一下,大都是使用该控件的key_down事件和CellEndEdit进 ...
- Delphi 开发ActiveX控件(非ActiveForm)
Delphi 开发ActiveX控件(非ActiveForm) Q:为什么不采用ActiveForm工程?通过它可以快速开发带窗体控件,创建过程也非常简单(都不用考虑安全接口问题),很省事! A:如果 ...
- extern字符串常量,宏定义字符串常量,怎么选
在使用常量的时候,我看到主要有两种写法: #define RKLICURegexEnumerationOptionsErrorKey @"RKLICURegexEnumerationOpti ...
- 9.7 dubbo心跳机制
dubbo的心跳机制: 目的:检测provider与consumer之间的connection连接是不是还连接着,如果连接断了,需要作出相应的处理. 原理: provider:dubbo的心跳默认是在 ...
- C++并发编程 条件变量 condition_variable,线程安全队列示例
1. 背景 c++11中提供了对线程与条件变量的更好支持,对于写多线程程序方便了很多. 再看c++并发编程,记一下学习笔记. 2. c++11 提供的相关api 3.1 wait wait用于无条件等 ...
- 连接mysql 出现:java.sql.SQLException: Unable to load authentication plugin 'caching_sha2_password'.
数据测试的时候出现: 网上查资料说的是mysql5.x 版本和 8.x版本的区别: 5.7版本是:default_authentication_plugin=mysql_native_password ...
- Windows批处理 调用程序后 不等待子进程 父进程继续执行命令
从DOS过来的老鸟应该都知道批处理,这个功能在WINDOWS中仍然保留着.批处理 说白了就是把一系列DOS命令写在一个文本文件里,然后把这个文件命名为XXX.bat(WINXP以后的系统也可以命名为* ...