just tried to run custom test case: [1,2,3,1,1,4,4,1]
which the correct result should return 1
but the 'expected answers' on leetcode OJ is 4....interesting
It appears to me that you have 4 1's and a total of 8 numbers. 8/2 = 4 and a majority element is defined as greater than the floor of n/2 not greater than or equal to the floor of n/2. Your test case doesn't have a correct answer and the prompt doesn't allow for this situation, so you shouldn't be testing for this situation.