【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 ...
随机推荐
- Airtest---UI自动化测试项目
Airtest Project是网易游戏团队新开源出来的一款用于UI自动化测试的项目. testerhome中的文档介绍:https://testerhome.com/topics/12486 官方链 ...
- struts--CRUD优化(图片上传)
1.上传方式 上传到指定文件目录,添加服务器与真实目录的映射关系,从而解耦上传文件与tomcat的关系 文件服务器 2.web代码优化 package com.yuan.crud.web; impo ...
- PHP 根据域名和IP返回不同的内容
遇到一个好玩的事情,访问别人的IP和别人的域名返回的内容竟然不一样.突然觉得很好玩,也很好奇.自己研究了一下下,就简单写一下吧~ 一个IP和一个域名, 先讲一下公网IP没有绑定域名,但是可以通过一个没 ...
- ipv4枯竭和ipv6的启用
IPv4是Internet Protocol version 4的缩写,中文翻译为互联网通信协议(TCP/IP协议)第四版,通常简称为网际协议版本4. IPv4使用32位(4字节)地址,因此地址空间中 ...
- HTML 005 标题
<h1>这是一个标题.</h1> <h2>这是一个标题.</h2> <h3>这是一个标题.</h3> HTML 标题 在 HTM ...
- 洛谷 P3956 棋盘 题解
每日一题 day5 打卡 Analysis 深搜+剪枝+瞎jb判断 1.越界 2.这个点无色 3.当前的价值已经比答案大 三种情况要剪枝 我搜索里判断要不要施法的时候没判断上一次有没有施法,白调了0. ...
- 二十七. Keepalived热备 Keepalived+LVS 、 HAProxy服务器
1.Keepalived高可用服务器 proxy:192.168.4.5(客户端主机) web1:192.168.4.100(Web服务器,部署Keepalived高可用软件) web2:192.16 ...
- [Codevs] 一塔湖图
http://codevs.cn/problem/1024/ floyd 走起 #include <iostream> #include <cstdio> #include & ...
- (RE) luogu P3690 【模板】Link Cut Tree
二次联通门 : luogu P3690 [模板]Link Cut Tree 莫名RE第8个点....如果有dalao帮忙查错的话万分感激 #include <cstdio> #includ ...
- linux系列(一):ls命令
ls命令是linux下最常用的命令.ls命令就是list的缩写,默认下ls用来打印出当前目录的清单,如果ls指定其他目录,那么就会显示指定目录里的文件及文件夹清单. 通过ls 命令不仅可以查看linu ...