There is a series of integers, the number of numbers is indefinite, a total of N, to find out the number of the most frequent (the original question is to find the number of occurrences greater than the N/2)
What is the general algorithm for this problem?
General algorithm
Loop array, find the same number for a number, find the total plus one, and mark the same number as-1, and then no longer compute in the loop
Repeat the loop until you find the result, and some of the tips can end prematurely, which means that if a number is more than N/2, it is definitely the result.
A Veteran's algorithm
He fully analyzed the same number of laws, the same number of their binary value, decimal value, hexadecimal values are equal
So that when you loop through the data, put the data into an array of 16 based on its hexadecimal lowest bit, so that after a loop, the array always records the number of occurrences of the data, such as the first digit of the hexadecimal number is 0, then add the place of the array "0" to one, Finally, compare the data to the largest number in the array until the end