题解 | #矩阵乘法#

矩阵乘法

https://www.nowcoder.com/practice/bf358c3ac73e491585943bac94e309b0

using System;
using System.Collections.Generic;


class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param a int整型二维数组 第一个矩阵
     * @param b int整型二维数组 第二个矩阵
     * @return int整型二维数组
     */
    public List<List<int>> solve (List<List<int>> a, List<List<int>> b) {
        // write code here
        if (a == null || b == null)
            return null;
        List<List<int>> lslsN = new List<List<int>>();
        for (int i = 0; i < a.Count; i++) {
            lslsN.Add(new List<int>());
            for (int j = 0; j < b[i].Count; j++) {
                int nSum = 0;
                for (int k = 0; k < a[i].Count; k++)
                    nSum += a[i][k] * b[k][j];
                lslsN[i].Add(nSum);
            }
        }
        return lslsN;
    }
}

全部评论

相关推荐

头像
04-29 10:53
已编辑
东北大学 自动化类
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务