6/17, LinkedIn 面经题
public class Solution {
public int[][] multiply(int[][] A, int[][] B) {
int rowsA = A.length;
int colsA = A[0].length;
int rowsB = B.length;
int colsB = B[0].length;
int[][] rst = new int[rowsA][colsB];
for(int i = 0; i < rowsA; i++){
for(int j = 0; j < colsB; j++){
for(int k = 0; k < colsA; k++){
if(A[i][k] == 0 || B[k][j] == 0) continue;
rst[i][j] += A[i][k] * B[k][j];
}
}
}
return rst;
}
}Last updated