I think this is an O(n) solution. but it runs 1169ms. why? How to improve it?

```
class Solution {
public:
int minMoves2(vector<int>& nums) {
int l=0,r=nums.size()-1,mid=nums.size()/2,pos;
while(true)
{
pos=partation(nums,l,r);
if(pos==mid) break;
if(pos>mid)
r=pos-1;
else
l=pos+1;
}
int res=0;
for(int i=0;i<pos;++i)
res+=nums[i]-nums[nums.size()-1-i];
return res;
}
int partation(vector<int>& nums,int left,int right)
{
int pivot=nums[left];
int l=left+1,r=right;
while(l<=r)
{
if(nums[l]<pivot&&nums[r]>pivot)
swap(nums[l++],nums[r--]);
if(nums[l]>=pivot) l++;
if(nums[r]<=pivot) r--;
}
swap(nums[left],nums[r]);
return r;
}
};
```