Write majorityOrNull(nums). It returns the value that appears strictly more than n / 2 times in nums, or null when no value does.
- A value that appears exactly
n / 2 times is not a majority, so [1, 1, 2, 2] has none - The values can be numbers, including negative numbers and 0, or strings (compare them with
===), and an empty array has no majority - Do not change the array
- Practice the divide-and-conquer way: if a value is a strict majority of a range, it is a strict majority of at least one of the two halves, so each half only needs to hand up one candidate, and the combine counts to confirm