Skip to content

Commit d1a2b04

Browse files
authored
Create solution.cpp
1 parent 2908d74 commit d1a2b04

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int minProductSum(vector<int>& nums1, vector<int>& nums2)
4+
{
5+
// sort both vectors in differing orders so the biggest values dont multiply with each other
6+
sort(nums1.begin(), nums1.end()); // sort accending order
7+
sort(nums2.rbegin(), nums2.rend()); // sort descending order
8+
9+
// Calc dot product sum
10+
int sum = 0;
11+
for (int i=0; i<nums1.size(); i++)
12+
{
13+
sum += nums1[i] * nums2[i];
14+
}
15+
16+
return sum;
17+
}
18+
};

0 commit comments

Comments
 (0)