내적하는 문제를 풀다가
나는 이렇게 하나씩 돌면서 곱했는데
#include <string>
#include <vector>
using namespace std;
int solution(vector<int> a, vector<int> b) {
int answer = 0;
for(int i=0; i<a.size(); i++)
{
answer += a[i] * b[i];
}
return answer;
}
이렇게 내적함수를 활용하는 방법이 있었다.
inner_product(a.begin(),a.end(),b.begin(),0);
#include <vector>
#include <numeric>
using namespace std;
int solution(vector<int> a, vector<int> b) {
return inner_product(a.begin(),a.end(),b.begin(),0);
}
#include <numeric> 을 사용해야 한다.