832. Flipping an Image - LeetCode
Question

Solution
题目大意:将1列与最后n列对换,2列与n-1列对换…然后再将每个元素取反
思路:遍历二维数组的左半边,对每个元素先做对换再取反
Java实现:
public int[][] flipAndInvertImage(int[][] A) {
// flip and reverse
for (int row=0; row<A.length; row++) {
for (int col=0; col<=A[row].length/2; col++) {
if (col == A[row].length/2 && A[row].length%2 == 0) break;
int end = A[row].length - 1 - col;
int tmp = A[row][col];
A[row][col] = invert(A[row][end]);
A[row][end] = invert(tmp);
System.out.print(A[row][col] + ", ");
}
System.out.println();
}
return A;
}
int invert(int x) {
return x == 1 ? 0 : 1;
}
832. Flipping an Image - LeetCode的更多相关文章
- Leetcode#832. Flipping an Image(翻转图像)
题目描述 给定一个二进制矩阵 A,我们想先水平翻转图像,然后反转图像并返回结果. 水平翻转图片就是将图片的每一行都进行翻转,即逆序.例如,水平翻转 [1, 1, 0] 的结果是 [0, 1, 1]. ...
- 【Leetcode_easy】832. Flipping an Image
problem 832. Flipping an Image solution1: class Solution { public: vector<vector<int>> f ...
- 【LeetCode】832. Flipping an Image 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 翻转 + 异或 直接计算 日期 题目地址:https ...
- LeetCode 832. Flipping an Image
Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resu ...
- LeetCode 832 Flipping an Image 解题报告
题目要求 Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the ...
- [LeetCode] 832. Flipping an Image_Easy
Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resu ...
- [LeetCode&Python] Problem 832. Flipping an Image
Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resu ...
- 832. Flipping an Image —— weekly contest 84
Flipping an Image Given a binary matrix A, we want to flip the image horizontally, then invert it, a ...
- 832. Flipping an Image
class Solution { public: vector<vector<int>> flipAndInvertImage(vector<vector<int& ...
随机推荐
- Idea学习之"重启或清理IEDA缓存"
idea的重启 如下图所示:第1步:通过File–>Invalidate Caches进入重启窗口: 第2步:选择自己所需要的重启方式,四个按钮,一共三种重启方式: 四个按钮的说明 Invali ...
- 定时任务__@Xxl-JOB的使用
概述xxl-job框架 首先我们要知道什么是XXL-JOB? 官方简介:XXL-JOB是一个分布式任务调度平台,其核心设计目标是开发迅速.学习简单.轻量级.易扩展.现已开放源代码并接入多家公司 ...
- 当心,你搞的Scrum可能是小瀑布
摘要:有的团队刚接触Scrum,一个问题令他们很困扰:迭代初期开发人员的工作较多,测试人员闲着:迭代末期开发人员闲着,测试人员的工作比较多,怎么解决资源等待的问题呢? 本文分享自华为云社区<当心 ...
- 『现学现忘』Docker基础 — 37、ONBUILD指令介绍
目录 1.ONBUILD指令说明 2.演示ONBUILD指令的使用 3.补充:crul命令解释 1.ONBUILD指令说明 ONBUILD是一个特殊的指令,它后面跟的是其它指令,比如 RUN, COP ...
- Numpy非常重要有用的数组合并操作
Numpy非常重要有用的数组合并操作 背景:在给机器学习准备数据的过程中,经常需要进行不同来源的数据合并的操作. 两类场景: 给已有的数据添加多行,比如增添一些样本数据进去: 给已有的数据添加多列,比 ...
- TTL 机制排毒,线上k8s的Job已经通过API 增加了Job的TTL 时长,且成功响应,为什么系统还是清理了Job?
TTL 机制排毒,线上k8s的Job已经通过API 增加了Job的TTL 时长,且成功响应,为什么系统还是清理了Job? 面试官:"已完成 Job 的 TTL 机制了解嘛?简单说说TTL存在 ...
- java中请给出一个return this的例子。
[新手可忽略不影响继续学习]下面例子中setYear中的return this;返回了一个指向对象的指针,this.setMonth(8).setDay(20);是合法的,如果像原来的例子一样什么都不 ...
- Paxos算法的一个简单小故事
一.Paxos是什么? Paxos,它是一个基于消息传递的一致性算法,Leslie Lamport在1990年提出,近几年被广泛应用于分布式计算中,Google的Chubby,Apache的Zooke ...
- Servlet 3.0以上版本使用@WebServlet注解配置映射
以前的Servlet都是在web.xml中进行配置,导致web.xml中各个Servlet的映射非常杂乱无章,后期也很难维护 本篇文章将详细阐述如何使用Servlet 3.0的新特性使用@WebSer ...
- 爬虫---scrapy架构和原理
scrapy是一个为了爬取网站数据, 提取结构性数据而编写的应用框架, 它是基于Twisted框架开发而来, 而Twisted框架是事件驱动的, 比较适合异步代码. 对会阻塞线程的操作, 包括访问数据 ...