All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 22, 2024
Last updated : June 22, 2024
Related Topics : Array, Greedy, Sorting
Acceptance Rate : 89.47 %
int compHelper(const void* a, const void* b) {
return *((int*) a) - *((int*) b);
}
int minProductSum(int* nums1, int nums1Size, int* nums2, int nums2Size){
int output = 0;
qsort(nums1, nums1Size, sizeof(int), compHelper);
qsort(nums2, nums2Size, sizeof(int), compHelper);
for (int i = 0; i < nums1Size; i++) {
output += nums1[i] * nums2[nums2Size - i - 1];
}
return output;
}
class Solution {
public int minProductSum(int[] nums1, int[] nums2) {
int output = 0;
Arrays.sort(nums1);
Arrays.sort(nums2);
for (int i = 0; i < nums1.length; i++) {
output += nums1[i] * nums2[nums2.length - i - 1];
}
return output;
}
}