Skip to content

Instantly share code, notes, and snippets.

@freelze
Last active September 21, 2017 09:27
Show Gist options
  • Save freelze/7b7feadaf09eb25c9fbd84ca55e1d03c to your computer and use it in GitHub Desktop.
Save freelze/7b7feadaf09eb25c9fbd84ca55e1d03c to your computer and use it in GitHub Desktop.
Runtime: 109 ms , Your runtime beats 4.36 % of cpp submissions.
#include <algorithm>
class Solution {
public:
int arrayPairSum(vector<int>& nums) {
vector<int>::size_type sz = nums.size();
sort(nums.begin(),nums.end());
int total = 0;
for(int i=0;i<sz;i+=2)
{
total+=nums[i];
}
return total;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment