Skip to content

Commit

Permalink
[프로그래머스 - Lv. 2] 행렬의 곱셈셈
Browse files Browse the repository at this point in the history
  • Loading branch information
jungmyunggi committed Dec 16, 2024
1 parent c2491e0 commit f5d59b5
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions jungmyunggi/Multiplication Of Matrices.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
arr1 = [
[2, 3, 2],
[4, 2, 4],
[3, 1, 4],
];
arr2 = [
[5, 4, 3],
[2, 4, 1],
[3, 1, 1],
];

function solution(arr1, arr2) {
var answer = [[]];
const r1 = arr1.length;
const c1 = arr1[0].length;
const r2 = arr2.length;
const c2 = arr2[0].length;
const temp = [];
for (let i = 0; i < r1; i++) {
temp.push(new Array(c2).fill(0));
}

for (let i = 0; i < r1; i++) {
for (let j = 0; j < c2; j++) {
for (let k = 0; k < c1; k++) {
temp[i][j] += arr1[i][k] * arr2[k][j];
}
}
}
answer = [...temp];
return answer;
}

console.log(solution(arr1, arr2));

0 comments on commit f5d59b5

Please sign in to comment.