My Code gets AC but it's wrong with test case [3,2,3]

```
class Solution {
public:
int majorityElement(vector<int>& nums) {
int i = 0, j = nums.size() - 1;
int x = nums[0];
while(i < j){
while(i < j && nums[j] > x)
j--;
if(i < j)
nums[i++] = nums[j];
while(i < j && nums[i] <= x)
i++;
if(i < j)
nums[j--] = nums[i];
}
nums[i] = x;
return nums[nums.size()/2];
}
};
```