R3-新增每日一题打卡。
目录

思路:
这题遍历主要从直角点开始遍历,用到了乘法原理。

乘法原理如下:

python
class Solution:
def numberOfRightTriangles(self, grid: List[List[int]]) -> int:
#最终结果是(col_sum-1)*(row_sum-1)
#先计算每一列的1之和
col_sum=[sum(col) for col in zip(*grid)]
ret=0
#每一行的
for row in grid:
row_sum=sum(row)
for r,c_s in zip(row,col_sum):
if r==1:
ret+=(row_sum-1)*(c_s-1)
return ret

ps:
python的zip操作
矩阵转置

并行遍历

对象组合

创建字典

处理不等迭代长度
