Find the most common entry in an array

前端 未结 8 1983
终归单人心
终归单人心 2020-12-07 10:43

You are given a 32-bit unsigned integer array with length up to 232, with the property that more than half of the entries in the array are equal to N, for some 32

8条回答
  •  自闭症患者
    2020-12-07 11:13

    Boyer and Moore's "Linear Time Majority Vote Algorithm" - go down the array maintaining your current guess at the answer.

提交回复
热议问题