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

  1. 661. Image Smoother【easy】

    661. Image Smoother[easy] Given a 2D integer matrix M representing the gray scale of an image, you n ...

  2. 【Leetcode_easy】661. Image Smoother

    problem 661. Image Smoother 题意:其实类似于图像处理的均值滤波. solution: 妙处在于使用了一个dirs变量来计算邻域数值,看起来更简洁! class Soluti ...

  3. LeetCode 661. Image Smoother (图像平滑器)

    Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother t ...

  4. LeetCode - 661. Image Smoother

    Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother t ...

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

  6. 661. Image Smoother色阶中和器

    [抄题]: Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoo ...

  7. 661. Image Smoother@python

    Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother t ...

  8. 【LeetCode】661. Image Smoother 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:暴力解决 日期 题目地址:https://l ...

  9. 【LEETCODE】52、数组分类,简单级别,题目:717,661,746,628,643,849

    package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...

随机推荐

  1. aspxGridview 根据单元格值得不同,设置单元格字体的颜色(设置和读取值)

    protected void ASPxGridView1_HtmlRowCreated(object sender,DevExpress.Web.ASPxGridView.ASPxGridViewTa ...

  2. python中index()、find()方法

    index() 方法检测字符串中是否包含子字符串 str ,如果指定 beg(开始) 和 end(结束) 范围,则检查是否包含在指定范围内,该方法与 python find()方法一样,只不过如果st ...

  3. mysql 存储过程分页 转载

    /* --名称:MYSQL版查询分页存储过程 by peace 2013-8-14 --输入参数:@fields -- 要查询的字段用逗号隔开 --输入参数:@tables -- 要查询的表 --输入 ...

  4. (4)shiro多个realm

    shiro支持多个realm,当设置多个realm的时候,shiro的认证和授权的步骤是怎样的呢. 多个realm认证原理: 发现需要在执行认证的时候,需要策略来处理多个realm存在的情况.默认实现 ...

  5. 解决PL/SQL导出cvs文件中文显示乱码

    方法 1 导出csv格式文件 新建excel文件 比如 a.xls excel软件打开 选择菜单数据 -导入外部数据  unicode默认下一步 选择 逗号分隔符 点击确定导入完成 方法 2 导出成h ...

  6. select 中添加option的注意

    在平时写JS中经常要给Select添加option,如果我们把option中的数据用一个字符串来表示: eg: var strOption='<option>1</option> ...

  7. java script sleep synchronous

    function sleep(milliseconds) { var start = new Date().getTime(); for (var i = 0; i < 1e7; i++) { ...

  8. R语言做条形图时候,离散变量和连续型变量的区别

    1)条形图 条形图或许是最常用图形,常用来展示分类(different categories on the x-axis)和数值(numeric values on the y-axis)之间的关系. ...

  9. Baidu URL的部分参数

    [Baidu URL的部分参数] 1.Baidu Form表单如下: 2.部分参数解析 wd  查询关键字,就是你要搜索的内容. bs 上一次搜索的词或者内容: rn  搜索结果页每页显示的数目,默认 ...

  10. 把Excel导入SQL server时出现错误

    在把Excel导入SQL server时出现“未在本地计算机上注册 Microsoft.ACE.OLEDB.12.0 ”该 错误信息:未在本地计算机上注册“microsoft.ACE.oledb.12 ...