Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother to make the gray scale of each cell becomes the average gray scale (rounding down) of all the 8 surrounding cells and itself. If a cell has less than 8 surrounding cells, then use as many as you can.
Example 1:
1 | Input: |
Note:
- The value in the given matrix is in the range of [0, 255].
- The length and width of the given matrix are in the range of [1, 150].
暴力解法
没什么难的, 判断好是否是边界元素,然后计算就行了
推荐写一个私有方法判断位置是否越界, 要不然if里面的条件太复杂
1 | class Solution { |