Aug 2, 2024
n/2 times in an array of integers.
n = 8, an element must appear more than 4 times.n = 9, the floor value is used, so it must appear more than 4 times.n/2 times.7, if 2 appears 4 times, 2 is the Majority Element.n/2, return that element.n/2, otherwise return -1 if no majority element exists.n/2 times.element and count.count to 0 and element to None.count is 0, choose the current element as the new element and set count to 1.element, increment count.count.element is indeed the majority by counting its occurrences again.n/2 times, it cannot be canceled out by other elements in pairs.