【Leetcode_easy】661. Image Smoother
2024-09-01 15:25:45
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;
完
最新文章
- Android从网络某个地址下载文件、写入SD卡
- Use Hibernate core API
- 安装coreseek找不到mysql
- 冒泡排序--c#
- 如何从 Xcode 控制台输出 JavaScript 的 log?
- C#调用DLL文件时参数对应表
- JavaJDBC整理
- 使用Windows Live Writer撰写的第一篇博文
- BeautifulSoup库的使用方法
- 托布利兹变换 toeplitz 变换
- instanceof与constructor的区别
- MySQL 5.6表空间传输
- 查看Linux进程CPU过高具体的线程堆栈(不中断程序)
- (转)Unity3d中的碰撞检测
- Js中的this关键字(吉木自学)
- 【Android】Android--Dialog
- AWT之—画图
- 【比赛】HNOI2018 游戏
- Xcode 生成 ipa包
- javascript总结29 :递归与回调函数
热门文章
- 【VS Code】中node.js代码自动补全的方法
- shell 学习笔记2
- 进击web与web协议
- [ Educational Codeforces Round 65 (Rated for Div. 2)][二分]
- [CSS] The :empty Pseudo Selector Gotchas
- 入门指引之查看accesstoken
- 记录从裸机到TensorFlow GPU版运行 的配置过程
- SQL server 中rowcount与@@rowcount 的使用
- web+文件夹上传
- 微信小程序分页显示