public int majorityElement(int[] nums) {
Arrays.sort(nums);
return nums[nums.length/2];
}
My two line java solution

I don't know why someone dislikes this solution. It's absolutely correct, and very clever actually.
When an element appears more than n/2 times in the array, the middle one must be the "majority" number when array is sorted.
Think about this example:
Assume O is the "majority" and X is other numbers. The two extreme cases:
O is at the front.
[O O O O X X X]
O is at the end.
[X X X O O O O]
They both must have the "majority" number in the middle.
All the other cases:
No matter how you shift X to the front or the end, O must be in the middle:
[X O O O O X X]
[X X O O O O X]
There's a mathematical proof. But probably I'll just skip it.