[Programmers] 행렬의 곱셈
Date:
[Programmers] 행렬의 곱셈
Problem URL : 행렬의 곱셈
#include <string>
#include <vector>
using namespace std;
vector<vector<int>> solution(vector<vector<int>> arr1, vector<vector<int>> arr2) {
vector<vector<int>> answer;
int r = arr1.size();
int c = arr1[0].size();
int c2 = arr2[0].size();
answer.resize(r);
for (int i = 0; i < r; i++) {
for (int j = 0; j < c2; j++){
int sum = 0;
for (int k = 0; k < c; k++) {
sum += arr1[i][k] * arr2[k][j];
}
answer[i].push_back(sum);
}
}
return answer;
}
댓글