给定两个 n*n 的矩阵 A 和 B ,求 A*B 。
数据范围:
,
要求:空间复杂度
, 时间复杂度
进阶:本题也有空间复杂度
,时间复杂度
的解法
PS:更优时间复杂度的算法这里并不考察
class Solution: def solve(self , a: List[List[int]], b: List[List[int]]) -> List[List[int]]: # write code here res = [[0]*len(b[0]) for i in range(len(a))] for i in range(len(a)): for j in range(len(b[0])): for k in range(len(b)): res[i][j] += a[i][k]*b[k][j] return res