Determine the most common occurrence in an array

前端 未结 9 985
南方客
南方客 2020-11-29 12:28

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

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

I need a function th

9条回答
  •  半阙折子戏
    2020-11-29 13:03

    You could do this: Convert your array to a list and sort it. Pick the first index, and call lastIndexOf(obj) on the value. Do this for each new value you encounter, calculate the range of the value and store the results of the biggest range in a variable.

提交回复
热议问题