Find duplicate in an array

后端 未结 5 1794
醉梦人生
醉梦人生 2021-01-14 16:45

Given a read only array of n + 1 integers between 1 and n, find one number that repeats in linear time using less than O(n) space and traversing the stream sequentially O(1)

5条回答
  •  离开以前
    2021-01-14 17:25

    std::vector isn't like any other vector.

    std::vector is a possibly space-efficient specialization of std::vector for the type bool.

    That's why it may use up less memory because it might represent multiple boolean values with one byte, like a bitset.

提交回复
热议问题