leetcode[Image Smoother]//待整理多种解法
来源:互联网 发布:大数据怎么搜索 编辑:程序博客网 时间:2024/06/10 02:51
解法一:
class Solution { public int[][] imageSmoother(int[][] M) { int[][] res = new int[M.length][M.length != 0 ? M[0].length : 0]; for(int i = 0; i < M.length; i++){ for(int j = 0; j < M[0].length; j++){ int sum = 0; int count = 0; if(i - 1 >= 0 && j - 1 >= 0){//左上方 count++; sum += M[i - 1][j - 1]; } if(i - 1 >= 0){//正上方 count++; sum += M[i - 1][j]; } if(i - 1 >= 0 && j + 1 < M[0].length){//右上方 count++; sum += M[i - 1][j + 1]; } if(j - 1 >= 0){//正左方 count++; sum += M[i][j - 1]; } count++;//自己 sum += M[i][j]; if(j + 1 < M[0].length){//正右方 count++; sum += M[i][j + 1]; } if(i + 1 < M.length && j - 1 >= 0){//左下方 count++; sum += M[i + 1][j - 1]; } if(i + 1 < M.length){//正下方 count++; sum += M[i + 1][j]; } if(i + 1 < M.length && j + 1 < M[0].length){//右下方 count++; sum += M[i + 1][j + 1]; } res[i][j] = (int) Math.floor(sum / 1.0 / count); } } return res; }}
阅读全文
0 0
- leetcode[Image Smoother]//待整理多种解法
- leetcode [Path Sum]//待整理多种解法
- leetcode [Majority Element]//待整理多种解法
- leetcode [Rotate Array]//待整理多种解法
- leetcode [Reverse Bits]//待整理多种解法
- leetcode [Happy Number]//待整理多种解法
- leetcode [Isomorphic Strings]//待整理多种解法
- leetcode [Contains Duplicate]//待整理多种解法
- leetcode[Add Digits]//待整理多种解法
- leetcode[Ugly Number]//待整理多种解法
- leetcode[Missing Number]//待整理多种解法
- leetcode[Word Pattern]//待整理多种解法
- leetcode[Ransom Note]//待整理多种解法
- leetcode[Longest Palindrome]//待整理多种解法
- leetcode[Fizz Buzz]//待整理多种解法
- leetcode[Add Strings]//待整理多种解法
- leetcode[Hamming Distance]//待整理多种解法
- leetcode[Island Perimeter]//待整理多种解法
- 如何更改ISE的IP核生成器中默认关联的PDF阅读器?
- 哈希表(hash table)概念详解(这可能是你能找到的最详细讲解)
- Python学习笔记——20170825
- 挖财2017校招前端工程师笔试试卷
- [cocos2dx_lua]Lua版自定义事件分发系统
- leetcode[Image Smoother]//待整理多种解法
- 简单的Shell命令
- 奇异值分解 SVD 的数学解释和numpy实例
- AbstractQueuedSynchronizer源码剖析(一)- 从抽象和接口说起
- [BZOJ1856][SCOI2010]字符串(组合数)
- 《统计学习方法》 支持向量机(SVM) Python实现
- 单链表总结(JAVA)
- 访问控制修饰符
- python安装