【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 ...
随机推荐
- seastar笔记
1.seastar::A.then([]{B});C:的核心思想是说我们开始了A之后就开始B,开始B之后就开始C,而不需要等A做完了再做B,B做完再做C 2.通常的return是一个需要执行的函数,例 ...
- 07_gitee源码参考
Django REST framework Tutorial 教程 码云:https://gitee.com/venicid/tutorial-api
- mysql删除完全重复数据保留一条
CREATE TABLE tmp AS (SELECT DISTINCT * FROM oa_organization);--将不重复的数据存入新建临时表tmp DELETE FROM oa_orga ...
- Java枚举抽象方法实战
需求背景 需求已经确定了几个固定的常量值,并且每个常量值都有相同的行为,但是具体实现细节不同.建议使用枚举抽象方法,优点:结构清晰,便于扩展. 枚举类实现抽象方法 与常规抽象类一样,enum类允许我们 ...
- Apache Flink - 内存管理
JVM: JAVA本身提供了垃圾回收机制来实现内存管理 现今的GC(如Java和.NET)使用分代收集(generation collection),依照对象存活时间的长短使用不同的垃圾收集算法,以达 ...
- 咏南中间件D7客户端演示
咏南中间件D7客户端演示 咏南中间件MORMOT(http.sys)支持D6.D7等老版本开发客户端.客户端使用TClientDataSet内存表控件,数据序列使用TynSerial类.
- CSRF in asp.net mvc and ap.net core
如果在方法上添加了[ValidateAntiForgeryToken],没处理好 请求没有带参数 2019-09-17 14:02:45,142 ERROR [36]: System.Web.Mvc. ...
- sql data compare
https://documentation.red-gate.com/sdc14 About SQL Data Compare With SQL Data Compare, you can compa ...
- Mercury:唯品会全链路应用监控系统解决方案详解(含PPT)
Mercury:唯品会全链路应用监控系统解决方案详解(含PPT) 原创: 姚捷 高可用架构 2016-08-08
- dom 加载监听事件 及解析
document.addEventListener("DOMContentLoaded", function (_event) { console.log("初始DOM ...