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& ...
随机推荐
- Numpy实现机器学习交叉验证的数据划分
Numpy实现K折交叉验证的数据划分 本实例使用Numpy的数组切片语法,实现了K折交叉验证的数据划分 背景:K折交叉验证 为什么需要这个?在机器学习中,因为如下原因,使用K折交叉验证能更好评估模型效 ...
- 全面系统讲解CSS工作应用+面试一步搞定
[TOC] 一.课程介绍 二.HTML基础强化 html常见元素和理解 html常见元素分类 head区元素:(不会在页面上留下元素) * meta * title * style * link * ...
- Wepy-小程序踩坑记
引言 用过原生开发的小程序也知道除了api 其他功能性的内容并不多对于需要做大型项目来说是比较难入手的,因此朋友推荐的wepy我就入坑鸟...这么一个跟vue的开发方式类似的框架,不过说起来跟vue类 ...
- 从kill-chain的角度检测APT攻击
前言 最近一直在考虑如何结合kill chain检测APT攻击.出发点是因为尽管APT是一种特殊.高级攻击手段,但是它还是会具有攻击的common feature,只要可以把握住共同特征,就能进行检测 ...
- Spark周总结(一)
本周学习内容: 1.搭建虚拟机Spark环境 2.idea编写Scala脚本并在yarn上运行 总结: 这周是回家第一周,虽然没啥事,但是还是想放松放松,也是万事开头难,跟着教程做,但总有几步跟教程上 ...
- java中请给出一个抽象类,可以继承实体类的例子
例1.7.2(抽象类可以继承实体类)- class VehMark_to_win { void steer() { System.out.println("Turn st ...
- 主线程中的Looper.loop()为什么不会造成ANR
引子: 正如我们所知,在android中如果主线程中进行耗时操作会引发ANR(Application Not Responding)异常. 造成ANR的原因一般有两种: 当前的事件没有机会得到处理(即 ...
- JS 实现下拉框去重
JS 实现下拉框去重 学习内容: 需求 总结: 学习内容: 需求 用 JS 下拉框去重 实现代码 <html> <head> <meta http-equiv=" ...
- WIN进程注入&BypassUAC&令牌窃取
WIN进程注入&BypassUAC&令牌窃取 本地提权-win令牌窃取 假冒令牌可以假冒一个网络中的另一个用户进行各类操作. 所以当一个攻击者需要域管理员的操作权限时候,需通过假冒域管 ...
- Blazor 发布WebAssembly使用Brotli 压缩提升初次加载速度
使用Brotli提高网站访问速度 在优化网站打开速度上,我们有很多的方法,而其中一个就是减少诸如Javascript和CSS等资源文件的大小,而减少文件大小的方法除了在代码上下功夫外,最常用的方法就是 ...