Question

832. Flipping an Image

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的更多相关文章

  1. Leetcode#832. Flipping an Image(翻转图像)

    题目描述 给定一个二进制矩阵 A,我们想先水平翻转图像,然后反转图像并返回结果. 水平翻转图片就是将图片的每一行都进行翻转,即逆序.例如,水平翻转 [1, 1, 0] 的结果是 [0, 1, 1]. ...

  2. 【Leetcode_easy】832. Flipping an Image

    problem 832. Flipping an Image solution1: class Solution { public: vector<vector<int>> f ...

  3. 【LeetCode】832. Flipping an Image 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 翻转 + 异或 直接计算 日期 题目地址:https ...

  4. LeetCode 832. Flipping an Image

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

  5. LeetCode 832 Flipping an Image 解题报告

    题目要求 Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the ...

  6. [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 ...

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

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

  9. 832. Flipping an Image

    class Solution { public: vector<vector<int>> flipAndInvertImage(vector<vector<int& ...

随机推荐

  1. ROS机器人操作系统相关书籍、资料和学习路径

    作者:Top Liu链接:https://zhuanlan.zhihu.com/p/30391098来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 本文是易科机器人实验 ...

  2. 决策树算法4:CHAID

    原理: 其中 n = a+b+c+d 卡方计算(例子)使用 sklearn完成 data.csv中的部分数据 #如何使用卡方检测相关度 from sklearn.feature_selection i ...

  3. 洋桃电子之STM32

    1.ARM内核与分类 作者:知乎用户链接:https://www.zhihu.com/question/52915983/answer/258507276来源:知乎著作权归作者所有.商业转载请联系作者 ...

  4. ps基础总结

    1.复制图层:首先选中移动工具(V),鼠标右键选中需要复制的图层(快捷方式:上面勾选自动选择),接着一只手按住Alt键,另一只手点击鼠标左键(不松开),往左往右移动即可.若是对多个图层起作用,就可将需 ...

  5. Spark入门之环境搭建

    本教程是虚拟机搭建Spark环境和用idea编写脚本 一.前提准备 需要已经有搭建好的虚拟机环境,具体见教程大数据学习之路又之从小白到用sqoop导出数据 - 我试试这个昵称好使不 - 博客园 (cn ...

  6. 【Weex笔记】-- Animate.css的使用

    animate.css是一个使用CSS3的animation制作的动画效果的CSS集合,里面预设了很多种常用的动画,且使用非常简单.本文将详细介绍animate.css的使用. 一,安装辅助依赖 np ...

  7. 安卓性能测试之Lint测试

    pre { direction: ltr; color: rgba(0, 0, 10, 1); text-align: left } pre.western { font-family: " ...

  8. 深入研究const(es6特性)

    const  申明常量 var str = 'es6' console.log(window.str) // es6 属于顶层对象window const不属于顶层对象window const str ...

  9. Java中的反射以及简单运用(原理+例子)

    Java反射 学习内容 1. 为什么要使用反射 2. 反射的概念 3. Java反射加载过程 4. 字节码对象理解 5. 获取字节码对象(.class)的三种方式 6. 反射常用API 8. 反射综合 ...

  10. webpack的安装 以及 问题 以及 作用

    参考链接: https://blog.csdn.net/Rnger/article/details/81086938     https://blog.csdn.net/qq_38111015/art ...