Guessing a number knowing only if the number proposed is lower or higher?

前端 未结 7 994
悲哀的现实
悲哀的现实 2021-01-02 21:34

I need to guess a number. I can only see if the number I\'m proposing is lower or higher. Performance matters a whole lot, so I thought of the following algorithm:

Le

7条回答
  •  旧巷少年郎
    2021-01-02 22:16

    Do you know the range of possible values? If yes, always start in the middle and do exactly what you describe.

提交回复
热议问题