Finding closest number in an array

前端 未结 11 910
萌比男神i
萌比男神i 2021-01-31 22:10

In an array first we have to find whether a desired number exists in that or not? If not then how will I find nearer number to the given desired number in Java?

11条回答
  •  清歌不尽
    2021-01-31 22:41

    Only thing missing is the semantics of closer.

    What do you do if you're looking for six and your array has both four and eight?

    Which one is closest?

提交回复
热议问题