```
public class Solution {
public int majorityElement(int[] num) {
Arrays.sort(num);
return num[num.length / 2];
}}
```

If to be considered majority element, a value has to occur at least N / 2 times in the array, then you can assume that if the array was to be sorted, the majority element would fill a contiguous block in the array up to (and potentially passed) the length of the array divided by 2.

So all I did was sort the array and return the element at the array position equal to the length of the array divided by 2. Very expressive code, since it's just 2 lines, but it still took about 240ms to do since the sort algorithm needed to take its time to complete.

Caveat: This solution only works if you can guarantee every time that there will be a majority element according to the rules set (at least N / 2 occurrences relative to the size of the array). If you can neither guarantee a majority element at all nor have the N / 2 rule in place, then this will not be suitable. If that's the case, you'll need to move onto a for-loop recording occurrences into a hash map. I tried a hash map solution which would tolerate neither of the above predicates being true, and it added about 90ms onto the running time from this solution.

Interesting problem.