algorithm to find the three majority elements in an array

后端 未结 2 612
醉话见心
醉话见心 2020-12-28 10:32

Let\'s say there are three elements in a non-sorted array all of which appear more than one-fourth times of the total number of elements.

What is the most efficient

2条回答
  •  天涯浪人
    2020-12-28 10:49

    create a histogram of the entries, sort it, and take the three largest entries.

提交回复
热议问题