题目描述

Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother to make the gray scale of each cell becomes the average gray scale (rounding down) of all the 8 surrounding cells and itself. If a cell has less than 8 surrounding cells, then use as many as you can.

Example 1:

Input:
[[1,1,1],[1,0,1],[1,1,1]]
Output:
[[0, 0, 0],[0, 0, 0],[0, 0, 0]]
Explanation:
For the point (0,0), (0,2), (2,0), (2,2): floor(3/4) = floor(0.75) = 0
For the point (0,1), (1,0), (1,2), (2,1): floor(5/6) = floor(0.83333333) = 0
For the point (1,1): floor(8/9) = floor(0.88888889) = 0

Note:

  1. The value in the given matrix is in the range of [0, 255].
  2. The length and width of the given matrix are in the range of [1, 150].

解析

注意:不需要先将四周补0。

class Solution {public:vector<vector<int>> imageSmoother(vector<vector<int>>& M) {vector<vector<int>> ans=M;for(int i=0;i<M.size();i++){for(int j=0;j<M[0].size();j++){int sum=0,cnt=0;for(int r=i-1;r<=i+1;r++){for(int c=j-1;c<=j+1;c++){if(r>=0&&r<M.size()&&c>=0&&c<M[0].size()) sum+=M[r][c],cnt++;}}ans[i][j]=sum/cnt;  //像素个数需要计算,不是9}}return ans;}
};

661. Image Smoother相关推荐

  1. LeetCode 661. Image Smoother

     题目描述 Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoo ...

  2. LeetCode 简单算法题

    使用Nodejs 抓取的LeetCode 简单算法题  一步一步来,先攻破所有简单的题目,有些题目不适合使用JS解决,请自行斟酌 Letcode 简单题汇总 104. Maximum Depth of ...

  3. Leetcode算法题-解法转载

    版权声明:本文为博主原创文章,未经博主允许不得转载.    https://blog.csdn.net/fuxuemingzhu/article/details/85112591 作者: 负雪明烛 i ...

  4. LeetCode All in One 题目讲解汇总(持续更新中...)

    原文地址:https://www.cnblogs.com/grandyang/p/4606334.html 终于将LeetCode的大部分题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开 ...

  5. leetcode (Image Smoother)

    Title:Image Smoother    661 Difficulty:Easy 原题leetcode地址:https://leetcode.com/problems/image-smoothe ...

  6. 数据库 版本号是 661,打不开。此server支持 655 和更早的版本号。不支持降级路径...

    "数据库 的版本号为 661,无法打开.此server支持 655 版及更低版本号. 不支持降级路径" 出现这种问题,通常是由于数据库版本号不同造成的. 我们能够用以下的语句查询数 ...

  7. SQLServer附加数据库提示“版本为661,无法打开,支持655版本……”

    在我们使用别人导出的数据库的时候,有时候我们会通过附加数据库的方法,把别人导出的数据库附加到我们的电脑中,这时,或许你会遇到这种问题,附加时,提示版本为XXX,无法打开,支持AAA版本. 这是怎么回事 ...

  8. C#LeetCode刷题之#661-图片平滑器( Image Smoother)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3730 访问. 包含整数的二维矩阵 M 表示一个图片的灰度.你需要 ...

  9. Android异常总结---W/System.err(661): java.lang.IllegalStateException: End of document.

    Android异常总结---W/System.err(661): java.lang.IllegalStateException: End of document. 5.03-22 21:42:10. ...

最新文章

  1. 解决idea中执行maven命令失败的问题
  2. PathFinding.js – 综合性的 JavaScript 路径查找库
  3. python基础语法第10关作业-【python基础语法】第11天作业练习题
  4. python爬虫基础(一)~爬虫概念和架构
  5. NPS cisco 802.1x window7 实现认证接入网络
  6. 修改DOS窗口编码格式
  7. 设计模式---观察者模式介绍与理解
  8. linux多线程加解锁
  9. Node.js文件操作二
  10. linux安装gd,linux下 安装GD
  11. python发送多人邮件没有展示收件人问题的解决方法
  12. Windows自带照片查看器恢复办法
  13. js 跨浏览器tab页通信
  14. 做Java开发如何月薪达到两万,需要什么技术水平
  15. 人工智能就业前景如何?
  16. Java实例——Java方法
  17. Hbase数据库完全分布式搭建以及java中操作Hbase
  18. 搭建股票数据api接口过程中会遇到什么问题?
  19. 数学速算法_小学初中高中 数学奥数教材及习题讲解(共42册PDF)
  20. 201671030107胡文艳《英文文本统计分析》结对项目报告

热门文章

  1. 双冠!网易互娱AI Lab包揽NTIRE 2022高动态范围成像(HDR)两项冠军
  2. 八股文(Java基础部分)
  3. OpenCV实现单目摄像头对图像目标测距
  4. 计算机怎么打开隐藏的项目,最全面win10怎么打开隐藏文件夹
  5. ++k与k++区别 和双目运算符结合
  6. 【openlayers】ol3切换图层源
  7. 每日分享:DNS解析记录
  8. 每日干货——每日分享技术干货App
  9. 解决Orcale登录界面乱码问题(linux)
  10. 浅谈BGP主机与其他双线主机的区别