Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4 Sum #1

Open
maopeilin1986 opened this issue May 11, 2016 · 1 comment
Open

4 Sum #1

maopeilin1986 opened this issue May 11, 2016 · 1 comment

Comments

@maopeilin1986
Copy link

我用了hash的方法也还是TLE,请问你有什么好的方法么?

@gzwl
Copy link
Owner

gzwl commented May 11, 2016

你好,这题我是用sort+two pointer夹逼来做的,第一次提交的时候跑了160ms,加上各种剪枝优化后24ms,time O(n^3)。哈希的方法复杂度应该也是time O(n^3) space O(n^2)的,因为一个值可能会对应多个pair,并且要考虑去重的问题,理论上也是可以过的,但是hash的话查询过程中常数会比较大,因此TLE的可能性比较大。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants