It is not a good question. But my solution is different


  • 0
    L

    class Solution {
    public:
    int arrayPairSum(vector<int>& nums) {
    std::sort(nums.begin(), nums.end());
    int res = 0;
    for (int i = 0; i < nums.size(); ++i) {
    if (i % 2 == 0) 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.