-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path750.cpp
More file actions
27 lines (27 loc) · 797 Bytes
/
750.cpp
File metadata and controls
27 lines (27 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution {
public:
int countCornerRectangles(vector<vector<int>>& grid) {//O(n4)
if(grid.empty() || grid[0].empty())
return 0;
int m = grid.size(), n = grid[0].size();
if(n==1 || m==1)
return 0;
int res = 0;
vector<vector<int>> rows(m), cols(n);
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
if(grid[i][j]==1){
for(auto c: rows[i]){
for(auto r:cols[j]){
if(grid[r][c]==1)
res++;
}
}
rows[i].push_back(j);
cols[j].push_back(i);
}
}
}
return res;
}
};