/**
* Return an array of arrays of size *returnSize.
* The sizes of the arrays are returned as *returnColumnSizes array.
* Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
*/
void get(int **M, int m, int n, int arr[m][n], int x, int y){
int cnt = 0, i, j, cnt2 = 0;
for(i=-1; i<=1; i++){
if(x+i < 0 || x+i >= m) continue;
for(j=-1; j<=1; j++){
if(y+j < 0 || y+j >= n) continue;
cnt2++;
cnt += arr[x+i][y+j];
}
}
M[x][y] = cnt/cnt2;
}
int** imageSmoother(int** M, int m, int* ns, int* returnSize, int** returnColumnSizes){
int arr[m][ns[0]];
int i,j;
for(i=0; i<m; i++){
for(j=0; j<ns[0]; j++){
arr[i][j] = M[i][j];
}
}
for(i=0; i<m; i++){
for(j=0; j<ns[0]; j++){
get(M, m, ns[0], arr, i, j);
}
}
*returnColumnSizes = ns;
*returnSize = m;
return M;
}
leetcode-661-图画平滑器-C语言
最新推荐文章于 2023-05-21 02:02:30 发布