leetcodeスパース行列の乗算



Leetcode Sparse Matrix Multiplication



| 1 0 0 | | 7 0 0 | | 7 0 0 | AB = | -1 0 3 | x | 0 0 0 | = | -7 0 3 | | 0 0 1 | Idea: i x k dimension matrix A is multiplied by k x j dimension matrix B to get i x j dimension matrix C, C[i][j]=A[i][0]*B[0][j] +... + A[i][k]*B[k][j], In order not to repeat the useless work with zero multiplication, first traverse A, A[i][k] The calculation is not 0, Traverse B again, if B[k][j] Is not 0, c[i][j] += A[i][k] * B[k][j]