-
Notifications
You must be signed in to change notification settings - Fork 0
/
3128. 直角三角形.cpp
35 lines (29 loc) · 994 Bytes
/
3128. 直角三角形.cpp
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
28
29
30
31
32
33
34
35
class Solution {
public:
int checkForRow(vector<vector<int>>&grid,int i , int j, int n , int m){
int count =0;
for(int k=0;k<m;k++) if(k!=j && grid[i][k]==1) count++;
return count;
}
int checkForCol(vector<vector<int>>&grid,int i , int j, int n ,int m){
int count=0;
for(int k=0;k<n;k++) if(i!=k && grid[k][j]==1) count++;
return count;
}
long long numberOfRightTriangles(vector<vector<int>>& grid) {
long long count =0;
int n = grid.size();
int m = grid[0].size();
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(grid[i][j]==1){
int row = checkForRow(grid,i,j,n,m);
int col = checkForCol(grid,i,j,n,m);
//cout<<row<<" "<<col<<endl;
if(row>=1 && col>=1) count+= row * col;
}
}
}
return count;
}
};