Given an array of size n, return the element that appears more than floor(n/2) times. Sorting moves all equal values together, making the majority easy to identify.
nums = array of integers
majority element
Example 1:
Input:
nums = [3,2,3]
Output:
3
Explanation:
3 appears twice, which is more than floor(3/2).
Example 2:
Input:
nums = [2,2,1,1,1,2,2]
Output:
2
Explanation:
2 appears four times, which is more than floor(7/2).