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. Table-Driven Design 表驱动设计

    注:本文所有代码来自 http://www.codeproject.com/Articles/42732/Table-driven-Approach 在许多程序中,经常需要处理那些拥有种种色色不同特性 ...

  2. Windows 域用户

    Windows 2000 组及说明 分类: Windows 2000 的组分为Security 和 Distribution 两种. Security 类型是Windows 2000 唯一用于赋予权限 ...

  3. 详述Oracle RAC的五大优势及其劣势

    不同的集群产品都有自己的特点,RAC的特点包括如下几点: ·双机并行.RAC是一种并行模式,并不是传统的主备模式.也就是说,RAC集群的所有成员都可以同时接收客户端的请求. ·高可用性.RAC是Ora ...

  4. drop user和drop user cascade的区别

    SQL> delete user itp2;delete user itp2       *第 1 行出现错误:ORA-00903: 表名无效 SQL> drop user itp2;dr ...

  5. keras各种优化方法总结 SGDmomentumnesterov

    http://blog.csdn.net/luo123n/article/details/48239963 前言 这里讨论的优化问题指的是,给定目标函数f(x),我们需要找到一组参数x,使得f(x)的 ...

  6. Concurrency and Race Conditions

    1.当多个线程访问共享硬件或软件资源的任何时候,由于线程之间可能产生对资源的不一致观察,所以必须显式管理对资源的访问. 2.内核中的并发管理设施: (1). 信号量: P操作将信号量的值减 1 ,判断 ...

  7. git cherry-pick用法

    场景: 如果你的应用已经发布了一个版本2.0, 代码分支叫release-2.0, 现在正在开发3.0, 代码的分支叫dev-3.0. 那么有一天产品说, 要把正在开发的某个特性提前上线, 也就是说要 ...

  8. idea 安装uml 画图工具

    centos7上: yum -y install graphviz mac上: brew install Graphviz file -> setting->plugins 安装plant ...

  9. Ansible develop module

    def cnf(action,configs,path): message = "Modify %s\n" %path changed = False if action == & ...

  10. Java8 Stream语法详解 2

    1. Stream初体验 我们先来看看Java里面是怎么定义Stream的: A sequence of elements supporting sequential and parallel agg ...