Array Homework Question

前端 未结 9 1270
庸人自扰
庸人自扰 2020-12-23 16:48

You are given an array with integers between 1 and 1,000,000. One integer is in the array twice. How can you determine which one? Can you think of a way to do it using littl

9条回答
  •  旧巷少年郎
    2020-12-23 17:13

    Sort integer by sorting them on place they should be. If you get "collision" than you found the correct number.

    space complexity O(1) (just same space that can be overwriten) time complexity less than O(n) becuse you will statisticaly found collison before getting on the end.

提交回复
热议问题