题解 | #矩阵乘法#
矩阵乘法
https://www.nowcoder.com/practice/bf358c3ac73e491585943bac94e309b0
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param a int整型二维数组 第一个矩阵 * @param b int整型二维数组 第二个矩阵 * @return int整型二维数组 */ public int[][] solve (int[][] a, int[][] b) { // write code here // 获取a数组的行 int rowA = a.length; // a的列等于b的行 int colA = a[0].length; // 获取b数组的列 int colB = b[0].length; // 结果数组 int[][] res = new int[rowA][colB]; for (int i = 0; i < rowA; i ++) { for (int j = 0; j < colB; j ++) { for (int k = 0; k < colA; k ++) { res[i][j] += a[i][k] * b[k][j]; } } } return res; } }