C++ 4-line easy Greedy solution


  • 0
    M
        int arrayPairSum(vector<int>& nums) {
            int res=0;
            sort(nums.begin(), nums.end());
            for(int i=0;i<nums.size();i+=2) res+=nums[i];
            return res;
        }

Log in to reply
 

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