brute force c++
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    bool check(int row, int col, vector<vector<int>>& image, int threshold,int &sum1){\n        for(int i=row;i<row+3;i++){\n            for(int j=col;j<col+3;j++){\n                if(i+1<row+3 && abs(image[i][j]-image[i+1][j]) >threshold) return false;\n                if(i-1>=row && abs(image[i][j]-image[i-1][j]) >threshold) return false;\n                if(j+1<col+3 && abs(image[i][j]-image[i][j+1]) >threshold) return false;\n                if(j-1>=col && abs(image[i][j]-image[i][j-1]) >threshold) return false;\n                sum1+=image[i][j];\n            }\n        }\n        return true;\n    }\n    void change(vector<vector<int>> &nums , vector<vector<int>> &sum, int row, int col, vector<vector<int>>& image,int sum1){\n        for(int i=row;i<row+3;i++){\n            for(int j=col;j<col+3;j++){\n                sum[i][j]+=(sum1/9);\n                nums[i][j]++;\n            }\n        }\n    }\n    vector<vector<int>> resultGrid(vector<vector<int>>& image, int threshold) {\n        int n=image.size();\n        int m=image[0].size();\n        vector<vector<int>> nums (n,vector<int> (m,0));\n        vector<vector<int>> sum (n,vector<int> (m,0));\n        for(int i=0;i<=n-3;i++){\n            for(int j=0;j<=m-3;j++){\n                //found a subgrid\n                int sum1=0;\n                if(check(i,j,image,threshold,sum1)){\n                    \n                    change(nums,sum,i,j,image,sum1);\n                }\n            }\n        }\n        vector<vector<int>>  ans(n,vector<int> (m,0));\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                if(nums[i][j]==0){\n                    ans[i][j]=image[i][j];\n                }\n                else{\n                    ans[i][j]=sum[i][j]/nums[i][j];\n                }\n                \n            }\n        }\n        return ans;\n    }\n};\n```
['C++']