原题链接

原题中文链接

一、题目描述

二、解题思路

题目所描述的意思是对每个数组先进行取反,并且对数组中的每个元素进行取反转换,所以一共要执行两个操作。

  • 使用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函数的用法。

Github代码

五、参考资料

二进制逆序(字节反转)

LeetCode_832. Flipping an Image_Solution的更多相关文章

  1. Flipping elements with WPF

    http://yichuanshen.de/blog/2010/11/13/flipping-elements-with-wpf/ Have you already seen ForgottenTim ...

  2. Codeforces Gym 100803G Flipping Parentheses 线段树+二分

    Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ...

  3. 【OpenMesh】Some basic operations: Flipping and collapsing edges

    这一节中你将学到一些OpenMesh中早已提供的基础操作. 内容包括三角形网格边的翻转以及通过连接邻接的顶点边缘折叠. 三角形网格的翻转(Flipping edges) 考虑到两个邻接面的三角形网格中 ...

  4. Flipping Game(枚举)

    Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  5. 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 ...

  6. Flipping Parentheses~Gym 100803G

    Description A string consisting only of parentheses '(' and ')' is called balanced if it is one of t ...

  7. [LeetCode] Flipping an Image 翻转图像

    Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resu ...

  8. [Swift]LeetCode832. 翻转图像 | Flipping an Image

    Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resu ...

  9. Flipping an Image

    Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resu ...

随机推荐

  1. bzoj1563: [NOI2009]诗人小G 决策单调性(1D1D)

    目录 题目链接 题解 代码 题目链接 bzoj1563: [NOI2009]诗人小G 题解 \(n^2\) 的dp长这样 \(f_i = min(f_j + (sum_i - sum_j - 1 - ...

  2. [BJOI2014]大融合

    Description 给你一个n个点的森林,要求支持m个操作: 1.连接两个点 x,y 2.询问若断掉 x,y这条边,两点所在联通块乘积的大小 Hint: \(n,m<=10^5\) Solu ...

  3. vs配置TFS

  4. ELASTIC 动态修改配置API

    工作中使用ELASTIC,我们常有需要修改的配置项,但有时又不想重启elastic,这时候就需要elasticsearch内置的修改集群配置API上场了. 这个API非常的简单. curl -XPUT ...

  5. 构造函数与getter和setter的区别

    构造函数是用于初始化类的属性,且只有在创建对象时才会调用构造函数,用于给对象分配地址 无参的构造函数,创建对象时默认调用,当程序没有明确写出有参的构造函数,系统会默认的创建一个. 有参的构造函数,创建 ...

  6. 使用 IntraWeb (33) - Cookie

    在 IW.HTTP.Cookie 单元提供有两个相关类: THTTPCookie.TCookieList; 另外 IWServerController 还有一个 CookieOptions 选项. 但 ...

  7. AngualrJS中制作一个有关菜单的Directive

    通常我们这样写一个菜单: <ul> <li data-ng-class="{'active': highlight('/orders')}"> <a ...

  8. android:碎片的概念

    碎片(Fragment)是一种可以嵌入在活动当中的 UI 片段,它能让程序更加合理和充分 地利用大屏幕的空间,因而在平板上应用的非常广泛.虽然碎片对你来说应该是个全新的概 念,但我相信你学习起来应该毫 ...

  9. pid 控制算法

    http://blog.csdn.net/huangkangying/article/details/78129148 https://zh.wikipedia.org/wiki/PID%E6%8E% ...

  10. 用PowerShell的命令行检查文件的校验MD5 SHA1 SHA256

    certutil -hashfile yourfilename.ext MD5 certutil -hashfile yourfilename.ext SHA1 certutil -hashfile ...