C++ easy to code.


  • 0
    X

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


Log in to reply
 

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