Skip to content

Commit cdf057a

Browse files
committed
561. Array Partition I
1 parent 8f4e5a4 commit cdf057a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

array-partition-i.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//Runtime: 76 ms
2+
class Solution {
3+
public:
4+
int arrayPairSum(vector<int>& nums) {
5+
sort(nums.begin(), nums.end());
6+
int res = 0;
7+
for (int i = 0; i < nums.size(); i++) {
8+
if (i % 2 == 0) {
9+
res += nums[i];
10+
}
11+
}
12+
return res;
13+
}
14+
};

0 commit comments

Comments
 (0)