3128. 直角三角形

直角三角形

解法一: 枚举

go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
func numberOfRightTriangles(grid [][]int) int64 {
rLen := len(grid)
cLen := len(grid[0])
rows := make([]int, rLen)
cols := make([]int, cLen)
for r := 0; r < rLen; r++ {
for c := 0; c < cLen; c++ {
rows[r] += grid[r][c]
cols[c] += grid[r][c]
}
}
ans := int64(0)
for r := 0; r < rLen; r++ {
for c := 0; c < cLen; c++ {
if grid[r][c] == 1 {
ans += int64((rows[r] - 1) * (cols[c] - 1))
}
}
}
return ans
}
作者

wuhunyu

发布于

2024-08-02

更新于

2024-09-05

许可协议