# Leetcode PHP题解--D123 661. Image Smoother

skys215

## D123 661. Image Smoother

### 题目链接

661. Image Smoother

### 最终代码

``````<?php
class Solution {

/**
* @param Integer[][] \$M
* @return Integer[][]
*/
function imageSmoother(\$M) {
\$N = \$M;
foreach(\$N as \$row => \$v){
foreach(\$v as \$col => \$v1){
//upRow
\$suroundedValues = [
isset(\$M[\$row-1][\$col-1]) ? \$M[\$row-1][\$col-1] : null,
isset(\$M[\$row-1][\$col  ]) ? \$M[\$row-1][\$col  ] : null,
isset(\$M[\$row-1][\$col+1]) ? \$M[\$row-1][\$col+1] : null,

isset(\$M[\$row  ][\$col-1]) ? \$M[\$row  ][\$col-1] : null,

isset(\$M[\$row  ][\$col+1]) ? \$M[\$row  ][\$col+1] : null,

isset(\$M[\$row+1][\$col-1]) ? \$M[\$row+1][\$col-1] : null,
isset(\$M[\$row+1][\$col  ]) ? \$M[\$row+1][\$col  ] : null,
isset(\$M[\$row+1][\$col+1]) ? \$M[\$row+1][\$col+1] : null,
];

\$filteredValues = array_filter(\$suroundedValues, function(\$values){
return !is_null(\$values);
});
\$filteredValues[] = \$v1;
\$N[\$row][\$col] = floor(array_sum(\$filteredValues)/count(\$filteredValues));
}
}
return \$N;
}
}``````

42 声望
26 粉丝
0 条评论