int countCornerRectangles(vector<vector<int>>& grid) {
if(grid.size() <= 1) return 0;
if(grid[0].size() <= 1) return 0;
int NI = grid.size(), NJ = grid[0].size();
int res=0;
for(int i=0; i<NI; i++) {
for(int ii=i+1; ii<NI; ii++) {
int n=0;
for(int j=0; j<NJ; j++) {
n += grid[i][j]*grid[ii][j];
}
res += n*(n-1)/2;
}
}
return res;
}
No comments:
Post a Comment