---
# System prepended metadata

title: '[561. Array Partition I](https://leetcode.com/problems/array-partition-i/)'

---

# [561. Array Partition I](https://leetcode.com/problems/array-partition-i/)
![](https://i.imgur.com/Dg8dnha.png)
![](https://i.imgur.com/FJru8eB.png)
int arrayPairSum(int* nums, int numsSize) {
    int i=0,j=numsSize-1;
    int sum=0;
    
    void sort(int i,int j,int* nums);
    sort(0,numsSize-1, nums);
    for(i=0;i<numsSize;i=i+2){
        sum+=nums[i];
    }
    
    return sum;
}
 
 
void sort(int i,int j,int* nums){
    int low=i;
    int high=j;
    int key=nums[i];
    int temp=0;
    
    if(i>j){
        return ;
    }
    while(i<j){
        while(nums[j]>key&&i<j){
            j--;
        }
        nums[i]=nums[j];
        while(nums[i]<=key&&i<j){
            i++;
            
        }
        nums[j]=nums[i];
        
    }
    
    nums[i]=key;
    sort(low,i-1,nums);
    sort(i+1,high,nums);
    
}
