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 * ...
随机推荐
- eclipse中添加aptana插件(html.css.js自动提示)
一.关于aptana aptana是一款很不错的插件,本人主要用于安装此类插件,在eclipse中用于编辑javascript代码,html代码,和css代码的,因为其有自动纠错功能,当然安装后的问题 ...
- myBatis连接MySQL报异常:No operations allowed after connection closed.Connection was implicitly closed
网站运行一个晚上,早上来上班,发现报错: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTra ...
- 让apache支持htaccess文件
第一:检测 apache是否开启mod_rewrite 通过php提供的phpinfo()函数查看环境配置,在"apache2handler -> Loaded Modules&quo ...
- gevent 实现单线程下的socket链接
通过gevent实现socket的多并发 server 端: import geventfrom gevent import socket, monkey monkey.patch_all() #进行 ...
- fb bin_debug下的swf不见了
fb清理了所选的项目,如果代码有错误,会自动删除bin_debug目录下的swf.这种情况,构建项目是无法自动生成swf的,只有将代码报错的地方修改正错了.选构建项目才会在bin_debug目录下生成 ...
- as3 连接mysql
http://www.cnblogs.com/yili16438/archive/2011/04/23/2025936.html
- 为什么NoSql快--磁盘顺序写
数据写入方式 1. update-in-place原地更新 2. append-only btree/copy on write tree顺序文件末尾追加 数据被按照特定方式放置,提升读性能, ...
- (4)shiro多个realm
shiro支持多个realm,当设置多个realm的时候,shiro的认证和授权的步骤是怎样的呢. 多个realm认证原理: 发现需要在执行认证的时候,需要策略来处理多个realm存在的情况.默认实现 ...
- 【343】MathJax、LaTex、Mathml 数学公式
参考:cnblog中添加数学公式支持 分类参考: 1. 基本功能 MathJax 我的LaTeX入门 MathJax basic tutorial and quick reference 分段函数:矩 ...
- JDBC连接数据库创建连接对象
1.加载JDBC驱动程序: 在连接数据库之前,首先要加载想要连接的数据库的驱动到JVM(Java虚拟机), 这通过java.lang.Class类的静态方法forName(String classN ...