3128. 直角三角形
题目链接:3128. 直角三角形
代码如下:
//参考链接:https://leetcode.cn/problems/right-triangles/solutions/2758892/cheng-fa-yuan-li-pythonjavacgo-by-endles-7469
class Solution
{
public:
long long numberOfRightTriangles(vector<vector<int>>& grid)
{
vector<int> col_sum(grid[0].size(), -1);// 提前减一
for (auto& row : grid)
{
for (int j = 0; j < row.size(); j++)
{
col_sum[j] += row[j];
}
}
long long res = 0;
for (auto& row : grid)
{
int row_sum = reduce(row.begin(), row.end(), 0) - 1;// 提前减一
for (int j = 0; j < row.size(); j++)
{
if (row[j] == 1) { res += col_sum[j] * row_sum; }
}
}
return res;
}
};
标签:3128,int,sum,long,grid,直角三角形,size,row
From: https://blog.csdn.net/weixin_45256307/article/details/141052138