Element with the largest number of occurrences in an integer Array
Retrieve the elements that appear most frequently in an integer array and return them in ascending order.
Implementation Method:
Public static int [] calcTimes (int [] num, int len );
[Input] num: an integer array;
Len: Number of Integers
[Return] returns the most frequently-occurring elements in an integer array in ascending order.
[Note] You only need to complete the function algorithm, and there is no IO input or output in the middle.
Example
Input: num = {, 3, 4, 4, 9, 9, 10} len = 10
Return Value: {4, 9}
# Include
# Include
# Include
# Define deusing namespace std; int main (int argc, char * argv []) {int num [] = {, 9 }; int len = sizeof (num)/sizeof (int); map
M; vector
Vec; for (int I = 0; I
Cnt) cnt = m [num [I];} for (map
: Iterator it = m. begin (); it! = M. end (); ++ it) {if (it-> second = cnt) vec. push_back (it-> first);} sort (vec. begin (), vec. end (); for (vector
: Iterator it = vec. begin (); it! = Vec. end (); ++ it) {cout <* it <
Test results: