✅✅Only Think (Brute-Force)✅✅
Complexity\n- Time complexity:O(NxNx3x3)\n\n- Space complexity:O(N*N)\n\n# Code\n\nclass Solution {\npublic:\n    vector<vector<int>> resultGrid(vector<vector<i
# Complexity\n- Time complexity:O(NxNx3x3)\n\n- Space complexity:O(N*N)\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> resultGrid(vector<vector<int>>& image, int threshold) {\n        int n = image.size(), m = image[0].size();\n        \n        vector<vector<int>> res = image;\n        vector<vector<int>> vis(n,vector<int>(m,0));\n        \n        for(int i=0; i<n-2; i++) {\n            for(int j=0; j<m-2; j++) {\n                int sum=0;\n                \n                bool flag=true;\n                for(int x=i; x<i+3; x++) {\n                    for(int y=j; y<j+3; y++) {\n                        int nRow = x+1;\n                        int nCol = y+1;\n                        \n                        if(nRow<i+3) {\n                            if(abs(image[nRow][y]-image[x][y])>threshold) {\n                                flag = false;\n                                break;\n                            }  \n                        }\n                        if(nCol<j+3) {\n                            if(abs(image[x][nCol]-image[x][y])>threshold) {\n                                flag = false;\n                                break;\n                            }\n                        }\n                        \n                        sum += image[x][y];\n                    }\n                }\n                \n                if(!flag) continue;\n                \n                sum = sum/9;\n                \n                for(int x=i; x<i+3; x++) {\n                    for(int y=j; y<j+3; y++) {\n            \n                        if(vis[x][y] == 0) {\n                            res[x][y] = sum;\n                        }\n                        else {\n                            res[x][y] += sum;\n                        }\n                        \n                        vis[x][y] += 1;\n                    }\n                }\n            }\n        }\n        \n        \n        for(int i=0; i<n; i++) {\n            for(int j=0; j<m; j++) {\n                if(vis[i][j]>0) {\n                    res[i][j] = res[i][j]/vis[i][j];\n                }\n            }\n        }\n        \n        return res;\n    }\n};\n```
['C++']