problem

661. Image Smoother

题意:其实类似于图像处理的均值滤波。

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;

最新文章

  1. Android从网络某个地址下载文件、写入SD卡
  2. Use Hibernate core API
  3. 安装coreseek找不到mysql
  4. 冒泡排序--c#
  5. 如何从 Xcode 控制台输出 JavaScript 的 log?
  6. C#调用DLL文件时参数对应表
  7. JavaJDBC整理
  8. 使用Windows Live Writer撰写的第一篇博文
  9. BeautifulSoup库的使用方法
  10. 托布利兹变换 toeplitz 变换
  11. instanceof与constructor的区别
  12. MySQL 5.6表空间传输
  13. 查看Linux进程CPU过高具体的线程堆栈(不中断程序)
  14. (转)Unity3d中的碰撞检测
  15. Js中的this关键字(吉木自学)
  16. 【Android】Android--Dialog
  17. AWT之—画图
  18. 【比赛】HNOI2018 游戏
  19. Xcode 生成 ipa包
  20. javascript总结29 :递归与回调函数

热门文章

  1. 【VS Code】中node.js代码自动补全的方法
  2. shell 学习笔记2
  3. 进击web与web协议
  4. [ Educational Codeforces Round 65 (Rated for Div. 2)][二分]
  5. [CSS] The :empty Pseudo Selector Gotchas
  6. 入门指引之查看accesstoken
  7. 记录从裸机到TensorFlow GPU版运行 的配置过程
  8. SQL server 中rowcount与@@rowcount 的使用
  9. web+文件夹上传
  10. 微信小程序分页显示