算法查找出现的最多的一排数字 - C ++最多、算法、数字

由网友(有一种爱叫堅持)分享简介:我需要做一个算法求解一个问题帮助:有一排与该行中出现不同的时间数字,我需要找到出现的数量最多,有多少次是该行中,例如:I need a help in making an algorithm for solving one problem: There is a row with numbers which appe...

我需要做一个算法求解一个问题帮助:有一排与该行中出现不同的时间数字,我需要找到出现的数量最多,有多少次是该行中,例如:

I need a help in making an algorithm for solving one problem: There is a row with numbers which appear different times in the row, and i need to find the number that appears the most and how many times it's in the row, ex:

1-1-5-1-3-7-2-1-8-9-1-2

1-1-5-1-3-7-2-1-8-9-1-2

这将是1和它出现5次。

That would be 1 and it appears 5 times.

该算法要快(这是我的问题)。 任何想法?

The algorithm should be fast (that's my problem). Any ideas ?

推荐答案

您可以保持哈希表并存储每个元素的计数在该结构中,像这样

You could keep hash table and store a count of every element in that structure, like this

h[1] = 5
h[5] = 1
...
阅读全文

相关推荐

最新文章