661. Image Smoother
static int wing=[]()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return ;
}(); class Solution
{
public:
bool valid(int i,int j,vector<vector<int>> &M)
{
if(i>=&&i<M.size()&&j>=&&j<M[].size())
return true;
return false;
} vector<vector<int>> imageSmoother(vector<vector<int>>& M)
{
int row=M.size(),col=M[].size();
vector<vector<int>> res(row); if(row==||col==)
return res;
for(int i=;i<row;i++)
{
vector<int> cur(col);
for(int j=;j<col;j++)
{
int sum=;
int count=;
for(int hor=-;hor<;hor++)
{
for(int dow=-;dow<;dow++)
{
if(valid(i+hor,j+dow,M))
{
count++;
sum+=M[i+hor][j+dow];
}
}
}
cur[j]=(sum/count);
}
res[i]=cur;
}
return res;
}
};
设置一个判定函数,有效元素才进行累加和统计
661. Image Smoother的更多相关文章
- 661. Image Smoother【easy】
661. Image Smoother[easy] Given a 2D integer matrix M representing the gray scale of an image, you n ...
- 【Leetcode_easy】661. Image Smoother
problem 661. Image Smoother 题意:其实类似于图像处理的均值滤波. solution: 妙处在于使用了一个dirs变量来计算邻域数值,看起来更简洁! class Soluti ...
- LeetCode 661. Image Smoother (图像平滑器)
Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother t ...
- LeetCode - 661. Image Smoother
Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother t ...
- [LeetCode&Python] Problem 661. Image Smoother
Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother t ...
- 661. Image Smoother色阶中和器
[抄题]: Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoo ...
- 661. Image Smoother@python
Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother t ...
- 【LeetCode】661. Image Smoother 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:暴力解决 日期 题目地址:https://l ...
- 【LEETCODE】52、数组分类,简单级别,题目:717,661,746,628,643,849
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
随机推荐
- leetcode973
public class POINT { public int X; public int Y; public int Z; } public class Solution { public int[ ...
- leetcode237
/** * Definition for singly-linked list. * public class ListNode { * public int val; * public ListNo ...
- grep命令打印前N行
想打印前5行,用head即可:grep xxx |head -n 5
- Firemonkey 绘图 TPathData
Firemonkey TPathData TPath控件 procedure TForm12.FormPaint( Sender : TObject; Canvas : TCanvas; const ...
- android中拷贝assets下的资源文件到SD卡中(可以超过1M)
很多手机游戏,在安装APK之后都得需要下载相应的资源包,然后才能进入游戏. 有这样一个需求:就是游戏中需要的资源包打在APK内,随apk一起进行安装到手机中. 这样就不需要,在安装APK之后,去下载资 ...
- C++Primer笔记-----继承
==========================================================================day11 面向对象程序设计============ ...
- 认识serviceLoader
最近在研究系统设计方面的东西,发现有很多通用的解决方案,包括spring配置扩展以及serviceLoader的应用,这里简单记录下serviceLoader的简单应用,网上例子很多,大同小异,本人觉 ...
- nginx访问静态文件配置
通过nginx访问静态文件配置,均是在server模块中配置,有两种方式: 1.alias 通过alias关键字,重定义路径,如 server{ listen 7001; server ...
- mysql创建定时器(event),查看定时器,打开定时器,设置定时器时间
由于项目需要创建定时器(evevt),所以就百度了一下,发现基本都是来源于一个模板,有些功能还不全,现在自己总结一下. 注:mysql版本是从5.1开始才支持event的.如果你的版本低于5.1就先升 ...
- github上关于iOS的各种开源项目集合(转)
UI 下拉刷新 EGOTableViewPullRefresh - 最早的下拉刷新控件. SVPullToRefresh - 下拉刷新控件. MJRefresh - 仅需一行代码就可以为UITable ...