Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int maxSideLength(vector<vector<int>>& mat, int threshold) {
- int maxLen = 0;
- #define a(i, j) ((i<0 || j<0) ? 0: mat[i][j])
- int n = mat.size(), m = mat[0].size();
- for(int i=0; i<n; i++)
- for(int j=0; j<m; j++){
- mat[i][j] += a(i-1,j) + a(i,j-1) - a(i-1,j-1);
- maxLen += ((maxLen <= min(i, j)) && (a(i,j)-a(i-maxLen-1,j)-a(i,j-1-maxLen)+a(i-1-maxLen,j-1-maxLen) <= threshold));
- }
- return maxLen;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement