O(NlogN)发现3个数字有数组中的任意T的总和总和、组中、发现、数字

2023-09-11 04:31:44 作者:后来我也彻底消失在你生活里,如你所愿,我想通了。下面小编为大

由于整数数组A,找到3人的总和任何吨。

Given an array A of integers, find any 3 of them that sum to any given T.

我看到这一些网上发帖,声称它有一个O(NlogN)的解决方案。

I saw this on some online post, which claims it has a O(NlogN) solution.

有关2号,我知道哈希表将有助于为O(N),但3个数字,我无法找到一个。

For 2 numbers, I know hashtable could help for O(N), but for 3 numbers, I cannot find one.

我也觉得这个问题听起来所熟悉的一些困难的问题,但不记得名字,因此不能谷歌它。 (而最差显然是O(N ^ 3),并与解决方案,以2号真的是O(N ^ 2))

I also feel this problem sounds familar to some hard problems, but cannot recall the name and therefore cannot google for it. (While the worst is obviously O(N^3), and with the solution to 2 numbers it is really O(N^2) )

这并没有真正解决任何问题,在现实世界中,只是我的错误。

It does not really solve anything in the real world, just bugs me..

你知道吗?

推荐答案

我觉得你的问题是等同于 3SUM问题。

I think your problem is equivalent to the 3SUM problem.