So easy with C++


  • 0
    Y
    class Solution {
    public:
        int arrayPairSum(vector<int>& nums) {
            int result = 0;
            sort(nums.begin(),nums.end());
            for (int i=0;i<nums.size();i+=2)
                result += nums[i];
            return result;
        }
    };
    

    >! Spoiler


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.