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 ...
随机推荐
- bzoj5312: 冒险(势能均摊线段树)
题目链接 BZOJ5312: 冒险 题解 如果一次操作对区间& 和 区间| 产生的影响是相同的,那么该操作对整个区间的影响都是相同的 对于每次操作,在某些位上的值,对于整个区间影响是相同的,对 ...
- 潭州课堂25班:Ph201805201 第七课:控制流程 (课堂笔记)
# 条件判断 s = '储蓄卡' if s == '男': # 如果if 表达式成立 ,则执行下级语句 print('男性') elif s == '女': # 如果上面表达式不成立,执行本次判断,本 ...
- navLI鼠标滑上显示下拉导航
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>l ...
- yum 安装 jenkins
环境:已安装 tomcat 安装(如果yum下载速度比较忙可以下载下来再安装) yum -y install https://pkg.jenkins.io/redhat/jenkins-2.77-1. ...
- asp.net c#并行调用service层代码
public ActionResult Home(AdviserSearchModel model) { //顾问列表需要的当前城市的下级地区 var ip = "117.82.196.19 ...
- 使用 IntraWeb (32) - Url 映射与 THandlers
最简单的 Url 映射是使用 TIWAppForm 的 class 方法: SetURL; THandlers 是 IntraWeb XIV 新增的内容处理器, 它能完成的不仅仅是 Url 映射(转发 ...
- AngularJS中有关Directive的汇总
本篇通过几个例子对AngularJS中的Directive进行汇总. 例子1,单向绑定和双向绑定 <html ng-app="myApp"> <head> ...
- Go学习入门
1. 为什么要学习Go Go语言宣称为互联网时代的C语言,那她有那些特性值得我们必须学习呢: 并行与分布式支持.除了我们日常熟悉的进程和线程,Go语言中提供了协程coroutine,从而简化了并行开发 ...
- centos7下安装gcc7
之前写过在linux下升级gcc 4.8至gcc 4.9的过程,现在gcc最新的版本是8,有些软件必须是gcc 7或者以上的版本才可以编译,比如clickhouse,gcc 7的安装过程和之前基本上一 ...
- WPF Dispatcher介绍
微软在WPF引入了Dispatcher,那么这个Dispatcher的主要作用是什么呢?Dispatcher的作用是用于管理线程工作项队列.主线程负责接收输入.处理事件.绘制屏幕等工作,这样一来,UI ...