```
public class Solution {
public int majorityElement(int[] nums) {
Arrays.sort(nums);
int count = 1;
int length = nums.length - 1;
if (length == 0) {
return nums[0];
} else {
while (length > 0) {
if (nums[length - 1] == nums[length]) {
count++;
} else {
if (count > nums.length / 2) {
break;
}
count = 1;
}
length--;
}
return nums[length + 1];
}
}
}
```