Given an array of 2n
elements, pair it in n elements and then find the sum of the minimum element in each pair and then maximize the sum. I wrote a class for this:
class Solution
{
public:
int sum = 0, n;
int arrayPairSum(vector<int>& nums)
{
sort(nums, nums + 2 * n);
for (i = 0; i < 2 * n; i = i + 2)
{
sum = sum + nums[i];
}
return sum;
}
};
but its showing me following error.
Line 5: Char 23: error: invalid operands to binary expression ('vector<int>' and 'int')
sort(nums,nums+2*n);
~~~~^~~~
/usr/bin/../lib/gcc/x86_6
How should I remove this error?