gpt4 book ai didi

algorithm - 在 O(n) 和常量空间中查找重复项

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:38:21 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Easy interview question got harder: given numbers 1..100, find the missing number(s)
Find the missing and duplicate elements in an array in linear time and constant space

我在一个论坛上看到一个有趣的问题。

你有从 1 到 100 的 100 个元素,但你不小心弄错了其中一个数字通过重复自身而与另一个重叠。例如。 1,99,3,...,99,100数组未排序,如何找到重复的数字?

我知道 Hash 可以做到 O(n) 时间和 O(n) 空间,我需要 O(1) 空间。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com