gpt4 book ai didi

algorithm - 时间复杂度和补码有什么关系?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:51:43 25 4
gpt4 key购买 nike

时间复杂度和补码有什么关系?

我不明白补语是什么意思。

我不明白下面的句子。

Approach #2 (Two-pass Hash Table) [Accepted]

To improve our run time complexity, we need a more efficient way to check if the complement exists in the array. If the complement exists, we need to look up its index. What is the best way to maintain a mapping of each element in the array to its index? A hash table.

https://leetcode.com/problems/two-sum/solution/

最佳答案

Complement 指的是添加到当前数字后将为您提供 target 值的其他数字。

如果(对于所有)a + b = target,那么a的补码是b.

为了查看是否存在一个数字的补码,而不是遍历数组(O(n)),他们存储它(源数组中的元素)是一个 HashMap 。

关于algorithm - 时间复杂度和补码有什么关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48838057/

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