class Solution { public: int MinNum(int a, int b) { if(a>b) return b; return a; } int arrayPairSum(vector<int>& nums) { sort(nums.begin(), nums.end()); int sum = 0; for(int i = 0; i < nums.size(); i+=2) { sum += MinNum(nums[i], nums[i+1]); } return sum; } };
class Solution { public: int arrayPairSum(vector<int>& nums) { int sum = 0; sort(nums.begin(), nums.end()); for(int i = 0; i < nums.size(); i+=2) { sum += nums[i]; } return sum; } };