searchchongfu数

Article Directory


Insert picture description here

  • If there are no repeating numbers under normal circumstances, then there are only n numbers from 1 to n,
  • When there is a repeated number, 1 ~ n has n + 1 numbers.
  • So that we can divide the n numbers from the middle number m into two halves,
  • If the number in 1-m exceeds m, then the repeated numbers appear in 1 ~ m,
  • Conversely, it appears in m + 1 ~ n.

  • For num, <= the number of elements in the array is count

  • When count> num, then 1-

  • When count <= num, the number of <= num is not yet

    • There is duplication in num + 1 to n
    • Conversely, there is a duplication from 1 to num-1

  • The problem becomes, you need to find a number num that satisfies:
    • <= num has more elements than num,
    • <= num-1 The number of elements is less than num.


Reference link

Published 589 original articles · 300 praises · 80,000 + views

Guess you like

Origin blog.csdn.net/zhoutianzi12/article/details/105493904