java - Determine the most common occurrence in an array -


Assume that I have an array of doubles that look like the following:

  Array [10] = {10, 10, 10, 3, 10, 10, 6, 10, 10, 9, 10}  

I need a function that can determine What is the MAJORTY vote that is the array, in this case "10" because this is the number that most often appears ... and of course there is a situation when no majority exists (where they are the same), Throw an exception in that situation Oga ...

Any clues? In addition to doing some very bad looping on the array (for each index, determine how many exist with the same value, count in the array, and then scan the count array for the highest number and position it In the value winner, etc ...)

a map & lt; Integer, integer & gt; It should be simple:

  int at most (int ... ary) {map  E: M. Context ()) {if (EG Value ()> Max) {Most Frequent = E. Geke (); Max = e.getValue (); }} Highest return; }  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -