problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::image_smoother::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static vector< vector< int > > imageSmoother (vector< vector< int > > &img)
 

详细描述

在文件 leetcode.h1902 行定义.

成员函数说明

◆ imageSmoother()

vector< vector< int > > leetcode::image_smoother::Solution::imageSmoother ( vector< vector< int > > &  img)
static

在文件 leetcode.cpp4985 行定义.

4985 {
4986 const int m = img.size();
4987 const int n = img[0].size();
4988 auto ans = vector(m, vector<int>(n));
4989 for(int i = 0; i < m; i++) {
4990 for(int j = 0; j < n; j++) {
4991 pair<int, int> cells[9] = {make_pair(i - 1, j - 1), make_pair(i - 1, j), make_pair(i - 1, j + 1),
4992 make_pair(i, j - 1), make_pair(i, j), make_pair(i, j + 1),
4993 make_pair(i + 1, j - 1), make_pair(i + 1, j), make_pair(i + 1, j + 1)};
4994 int sum = 0;
4995 int count = 0;
4996 for(int k = 0; k < 9; k++) {
4997 auto [x, y] = cells[k];
4998 if(0 <= x && x < m && 0 <= y && y < n) {
4999 count++;
5000 sum += img[x][y];
5001 }
5002 }
5003 ans[i][j] = sum / count;
5004 }
5005 }
5006 return ans;
5007 }

被这些函数引用 leetcode::image_smoother::TEST().


该类的文档由以下文件生成: