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

1982.Find-Array-Given-Subset-Sums.cpp is TLE #27

Closed
JIACHENG135 opened this issue Jan 24, 2022 · 2 comments
Closed

1982.Find-Array-Given-Subset-Sums.cpp is TLE #27

JIACHENG135 opened this issue Jan 24, 2022 · 2 comments

Comments

@JIACHENG135
Copy link

Hello wisdompeak,

Thanks for your sharing! I have learned a lot from your codes. I tried to follow your method for leetcode 1982 but find your solution is now graded as TLE. Which step do you think can be improved in order to get accepted? Once i figured it out, i will close this ticket. Thanks again.
image

@wisdompeak
Copy link
Owner

wisdompeak commented Jan 29, 2022

我新增了改进的写法,见 https://github.com/wisdompeak/LeetCode/blob/master/Greedy/1982.Find-Array-Given-Subset-Sums/1982.Find-Array-Given-Subset-Sums_v2.cpp
基本原理和2007和2122差不多,就是用双指针而不是multiset,把混合了{nums[i]}与{nums[i]+x}的数组分离出{nums[i]}来。这样避免了每一轮的实时排序。

@wisdompeak
Copy link
Owner

请参见更新后的代码。

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