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& ...
随机推荐
- 设计模式之:工厂方法模式FactoryMethodPattern的实现
本例用到了配置文件.接口.反射.多态: 满足的设计原则: 通过工厂,实现创建对象和使用对象的分离,实现松耦合,满足迪米特法则: 通过配置文件指定创建对象类型,而不需更改源代码,满足开闭原则: 容易实现 ...
- 【Android开发】通过 style 设置状态栏,导航栏等的颜色
<style name="test"> <!--状态栏颜色--> <item name="colorPrimaryDark"> ...
- 将百度地图Demo抽取出来安到自己的程序中
今日所学: 使用百度地图ADK实现手机定位 [Android]使用百度.高德.腾讯地图SDK获取定位数据与屏幕截图分享到QQ_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili 代码获取SHA1 (2 ...
- 面向对象编程-终结篇 es6新增语法
各位,各位,终于把js完成了一个段落了,这次的章节一过我还没确定下面要学的内容可能是vue也可能是前后端交互,但无论是哪个都挺兴奋的,因为面临着终于可以做点看得过去的大点的案例项目了,先憋住激动地情绪 ...
- 小白文-Git-版本控制
推荐阅读 Git学习-图文并茂还有游戏玩! Git版本控制 注意:开始学习之前,确保自己的网络可以畅通的连接Github:https://github.com,这个是一个国外网站,连起来特别卡,至于用 ...
- 用asmlib方式创建oracle集群ASM磁盘(oracleasm)
创建asm磁盘的几种方式 创建asm方式很多主要有以下几种 1.Faking方式 2.裸设备方式 3.udev方式(它下面有两种方式) 3.1 uuid方式 3.2 raw方式(裸设备方式) 4.as ...
- 帝国CMS如何互相转移分表之间的数据
最近发现帝国CMS文章数据添加太多到某一张分表中了,如图 这是极其不合理的,需要优化下,所以这篇文章要告诉大家的也就是如何互相转移分表之间的数据. 我现在要将:phome_ecms_news_data ...
- Java学习day18
学习了三种简单的布局结构 做了一个简单的多按键窗口 Panel无法单独存在而显示出来,需要借助一个容器,例如Frame 明天学习输入框监听和画笔
- 快速排序算法 - go实现
在分析redis集群中大Key的时候,通常都采用分析rdb文件的方式:但是这种方式需要在每一台redis服务器上部署分析程序及分析脚本,而像salt之类的工具运维没有开放给我们使用,一台一台部署不好管 ...
- 搜索与图论②--宽度优先搜索(BFS)
宽度优先搜索 例题一(献给阿尔吉侬的花束) 阿尔吉侬是一只聪明又慵懒的小白鼠,它最擅长的就是走各种各样的迷宫. 今天它要挑战一个非常大的迷宫,研究员们为了鼓励阿尔吉侬尽快到达终点,就在终点放了一块阿尔 ...