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. Redis 通用操作2

    01, 一次设置多个键值 => mset key1 value1 key2 value2 key3 value3 ...... 02, 一次获取多个值 => mget ke1 key2 k ...

  2. MySQL优化十大技巧

    转自:https://m.2cto.com/database/201701/557910.html MYSQL优化主要分为以下四大方面: 设计:存储引擎,字段类型,范式与逆范式 功能:索引,缓存,分区 ...

  3. nodejs发送http请求

    var request = require('request'); var options = { method: 'post', url: u, form: content, headers: { ...

  4. delphi Firemonkey ListBoxItem自绘

    delphi Firemonkey ListBoxItem自绘 ListBoxItem1的事件ListBoxItem1Paint procedure TForm1.ListBoxItem1Paint( ...

  5. C# 通用方法

    一. /// <summary> /// 删除字符串中的中文 /// </summary> public static string Delete(string str) { ...

  6. unity 设置屏幕旋转

    只允许竖屏: Portrait                    √ Portrait Upside Down √ Landscape Right        × Landscape Left ...

  7. STS或eclipse安装SVN插件

    安装sts--SVN插件 简介:sts是与eclipse类似的Java IDE开发工具(不了解的百度) 1.sts菜单栏 help->install New Software 依据大家的版本选择 ...

  8. 常用类一一MATH类一一两个静态常量PI 和E,一些数学函数。

    package test; public class MathTest { public static void main(String[] args) { System.out.println(Ma ...

  9. 关于struts2中ActionContext类的作用

    关于struts2中ActionContext类的作用有三个: 1.获取三大作用域对象及页面参数 2.是struts标签的上下文对象 3.ThreadLocal内装的就是ActionContext 怎 ...

  10. rook 记录

    更改rook 集群的配置 https://github.com/rook/rook/blob/master/design/cluster-update.md rook集群升级流程 https://ro ...