【Leetcode_easy】661. Image Smoother
problem
题意:其实类似于图像处理的均值滤波。
solution:
妙处在于使用了一个dirs变量来计算邻域数值,看起来更简洁!
class Solution {
public:
vector<vector<int>> imageSmoother(vector<vector<int>>& M) {
if(M.empty() || M[].empty()) return {};
vector<vector<int>> res = M, dirs = {{-, -}, {-, }, {-, }, {, -},
{, }, {, -}, {, }, {, } };//dirs err.
int m = M.size(), n = M[].size();
for(int i=; i<m; i++)
{
for(int j=; j<n; j++)
{
int sum = M[i][j], num = ;//err.
for(auto dir : dirs)
{
int x = i+dir[], y = j+dir[];
if(x< || x>=m || y< || y>=n) continue;//err.
num++;
sum += M[x][y];
}
res[i][j] = sum / num;
}
}
return res;
}
};
参考
1. Leetcode_easy_661. Image Smoother;
完
【Leetcode_easy】661. Image Smoother的更多相关文章
- 【LeetCode】661. Image Smoother 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:暴力解决 日期 题目地址:https://l ...
- 【Leetcode_easy】1021. Remove Outermost Parentheses
problem 1021. Remove Outermost Parentheses 参考 1. Leetcode_easy_1021. Remove Outermost Parentheses; 完
- 【Leetcode_easy】1022. Sum of Root To Leaf Binary Numbers
problem 1022. Sum of Root To Leaf Binary Numbers 参考 1. Leetcode_easy_1022. Sum of Root To Leaf Binar ...
- 【Leetcode_easy】1025. Divisor Game
problem 1025. Divisor Game 参考 1. Leetcode_easy_1025. Divisor Game; 完
- 【Leetcode_easy】1029. Two City Scheduling
problem 1029. Two City Scheduling 参考 1. Leetcode_easy_1029. Two City Scheduling; 完
- 【Leetcode_easy】1030. Matrix Cells in Distance Order
problem 1030. Matrix Cells in Distance Order 参考 1. Leetcode_easy_1030. Matrix Cells in Distance Orde ...
- 【Leetcode_easy】1033. Moving Stones Until Consecutive
problem 1033. Moving Stones Until Consecutive 参考 1. Leetcode_easy_1033. Moving Stones Until Consecut ...
- 【Leetcode_easy】1037. Valid Boomerang
problem 1037. Valid Boomerang 参考 1. Leetcode_easy_1037. Valid Boomerang; 完
- 【Leetcode_easy】1042. Flower Planting With No Adjacent
problem 1042. Flower Planting With No Adjacent 参考 1. Leetcode_easy_1042. Flower Planting With No Adj ...
随机推荐
- 学到了林海峰,武沛齐讲的Day31 完 TCP UDP
多用户链接 验证等.学习了思路.还是很有用的..
- Oracle 与 postgreSQL 事务处理区别(多版本与undo区别)
2015年左右,因为工作需要用MongoDB.CouchBase这两种文档型数据库,时不时到这两个数据库官网上查资料.报BUG.时常可以在MongoDB官网上看到这样一些新闻,“某某企业成功将MySQ ...
- PostgreSQL、Greenplum 日常监控 和 维护任务
背景 Greenplum的日常监控点.评判标准,日常维护任务. 展示图层 由于一台主机可能跑多个实例,建议分层展示. 另外,即使是ON ECS虚拟机(一个虚拟机一个实例一对一的形态)的产品形态,实际上 ...
- Greenplum 如何直连segment节点
Greenplum 展开阅读全文 直连greenplum segment节点的方法, utility模式 : 使用这种方式,不与其他节点通讯,只操作当前节点.也没有数据分布的概念. 如果使用uti ...
- 三十九.NoSQL概述 部署Redis服务 、 部署LNMP+Redis
1. 搭建Redis服务器 在主机 192.168.4.50 上安装并启用 redis 服务 设置变量test,值为123 查看变量test的值 1.1 搭建redis服务器 1.1.1 安装re ...
- python3 中的bytes类型
- 通过Confulence API统计用户文档贡献量
Confulence提供了非常清晰的RESTful API,直接使用API比confluence_python_cli这个库更方便. 参考文档:https://developer.atlassian. ...
- ZR#957
ZR#957 解法: 首先 $ T $ 必须得要是 $ S $ 的子序列,不然不存在好的下标序列,因此一定无解. 考虑判断一个串 $ T $ 是不是 $ S $ 子序列的贪心做法:每次从没有匹配的位置 ...
- Dockerfile HEALTHCHECK详解
Dockerfile中使用HEALTHCHECK的形式有两种: 1.HEALTHCHECK [options] CMD command(本次详细解释) 2.HEALTHCHECK NODE 意思是禁止 ...
- Cubic-bezier 曲线
cubic-bezier又称三次贝塞尔,主要是为animation生成速度曲线函数. cubic-bezier(x1,y1,x2,y2) 此图中: P0:(0,0) P1:(x1,y1) P2:(x2 ...