832. Flipping an Image
2019-08-16 11:15:23来源:博客园 阅读 ()
832. Flipping an Image
Posted on 2019-07-26 15:07 玛格汉程序猿 阅读(...) 评论(...) 编辑 收藏1 public class FlipAndInvertImage { 2 /** 3 * 832. Flipping an Image 4 * Easy 5 * Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resulting image. 6 * To flip an image horizontally means that each row of the image is reversed. For example, flipping [1, 1, 0] horizontally results in [0, 1, 1]. 7 * To invert an image means that each 0 is replaced by 1, and each 1 is replaced by 0. For example, inverting [0, 1, 1] results in [1, 0, 0]. 8 * Example 1: 9 * Input: [[1,1,0],[1,0,1],[0,0,0]] 10 * Output: [[1,0,0],[0,1,0],[1,1,1]] 11 * Explanation: First reverse each row: [[0,1,1],[1,0,1],[0,0,0]]. 12 * Then, invert the image: [[1,0,0],[0,1,0],[1,1,1]] 13 * Example 2: 14 * Input: [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]] 15 * Output: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]] 16 * Explanation: First reverse each row: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]]. 17 * Then invert the image: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]] 18 * Notes: 19 * 1 <= A.length = A[0].length <= 20 20 * 0 <= A[i][j] <= 1 21 */ 22 public int[][] solution(int[][] A) { 23 int aLen = A.length; 24 if (aLen==0) 25 return new int[0][0]; 26 int aWei = A[0].length; 27 int[][] res = new int[aLen][aWei]; 28 for (int l=0; l<aLen; l++){ 29 for (int w=0; w<aWei; w++){ 30 if (A[l][w] == 1) 31 res[l][aWei-1-w] = 0; 32 else 33 res[l][aWei-1-w] = 1; 34 } 35 } 36 return res; 37 } 38 }
原文链接:https://www.cnblogs.com/bangpenggao/p/11250449.html
如有疑问请与原作者联系
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:java分页查询代码
- ImageView基本用法 2019-09-02
- java8 中 ImageIO 读取 tiff 格式的图片失败 2019-08-16
- feign响应Image流对象 2019-08-16
- Servlet如何凭空制造一个图像Image? 2018-12-17
- word转PDF,PDF转Image,使用oppenOffice注意事项等 2018-10-03
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash