O(NlogN)发现3个数字有数组中的任意T的总和 [英] O(NlogN) finding 3 numbers that have a sum of any arbitrary T in an array

查看:101
本文介绍了O(NlogN)发现3个数字有数组中的任意T的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于整数数组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.

这篇关于O(NlogN)发现3个数字有数组中的任意T的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆