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 ...
随机推荐
- AGC015 C-Nuske vs Phantom Thnook AtCoder 思路 前缀和
目录 题目链接 题解 代码 题目链接 AGC015 C-Nuske vs Phantom Thnook AtCoder 题解 树的性质有: 如果每个蓝色连通块都是树,那么连通块个数=总点数−总边数. ...
- BZOJ.3064.CPU监控(线段树 历史最值)
题目链接 \(Description\) 有一个长为n的序列Ai,要求支持查询[l,r]的最值.历史最值,区间加/重设 \(Solution\) 线段树,每个点再维护一个历史(从0到现在)最大值.历史 ...
- 洛谷.3690.[模板]Link Cut Tree(动态树)
题目链接 LCT(良心总结) #include <cstdio> #include <cctype> #include <algorithm> #define gc ...
- angular.js--------demo1
<!doctype html><html ng-app> <head> <meta charset="utf-8"> </he ...
- RxJava2学习笔记(2)
上一篇已经熟悉了Observable的基本用法,但是如果仅仅只是“生产-消费”的模型,这就体现不出优势了,java有100种办法可以玩这个:) 一.更简单的多线程 正常情况下,生产者与消费者都在同一个 ...
- 绘图 Painter转接口封装的方式
记录下思想 适用于业务逻辑相对单纯的一些画法,比如画背景(颜色,背景,边框等) 一个Draw方法中如果绘制比较复杂的话,就会导致代码混乱,而不灵活,每次需求更改就得重新画过,可重用性差. 以接 ...
- AngularJS中$interval的用法
在AngularJS中$interval用来处理间歇性处理一些事情. 最常用的是: var app = angular.module("app",[]); app.controll ...
- Github如何回退/回滚到某个版本
当然你可以直接在命令行使用 git reset --hard <commit ID号> 或者 git reset --hard HEAD^来进行回退
- Excel如何固定表头,任意一行
在日常Excel操作中,有时候内容比较多,需要将表头固定才能方便查看.那么,该如何固定表头呢?或者说如何固定任意一行我们制定的呢?下面以Excel2013进行详细的步骤讲解. 首先打开需要操作的Exc ...
- 给iOS开发者的Android开发建议
本人从事iOS应用开发已经5年有余,直到现在还总是刻意回避Andriod应用的开发.但是不管你信不信,安卓开发还是很有意思的,从iOS转向Android应用开发的跨度并没有你想象的那么大. 现在我把在 ...