Efficient search of sorted numerical values

后端 未结 4 758
不思量自难忘°
不思量自难忘° 2021-02-06 15:06

I have an int[] array that contains values with the following properties:

  • They are sorted
  • They are unique (
4条回答
  •  佛祖请我去吃肉
    2021-02-06 15:28

    If int[] is

    • sorted
    • have unique values
    • you know the range (in advance)

    Than instead of searching why not to save the value at its index.

    Say the number is 243 than save the value in int[243] = 243.

    That way searching will be easy and faster. Only thing left is to find out next higher value.

提交回复
热议问题