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 }
|