TVP

# SUM系列，下篇

3 Sum

https://leetcode.com/problems/3sum/description/

4 Sum

https://leetcode.com/problems/4sum/description/

3 Sum Closest 寻找最接近的结果

https://leetcode.com/problems/3sum-closest/description/

Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.

Note: The solution set must not contain duplicate triplets.

For example, given array S = [-1, 0, 1, 2, -1, -4],

A solution set is:

[

[-1, 0, 1],

[-1, -1, 2]

]

4SUM 与 3Sum，类似， 这里面最重要的测试数据就是 。 而上文提到的关于重复数据的监测，也有三处。大家写代码的时候，一定要注意。

Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.

Note: The solution set must not contain duplicate quadruplets.

For example, given array S = [1, 0, -1, 0, -2, 2], and target = 0.

A solution set is:

[

[-1, 0, 0, 1],

[-2, -1, 1, 2],

[-2, 0, 0, 2]

]

Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution.

For example, given array S = {-1 2 1 -4}, and target = 1.

The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).

3Sum Smaller

https://leetcode.com/problems/3sum-smaller/description/

4Sum II

https://leetcode.com/problems/4sum-ii/description/

（亲，领一个呗~亲~~）

• 发表于:
• 原文链接http://kuaibao.qq.com/s/20180110G01QQZ00?refer=cp_1026
• 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号（企鹅号）传播渠道之一，根据《腾讯内容开放平台服务协议》转载发布内容。
• 如有侵权，请联系 cloudcommunity@tencent.com 删除。

2023-02-03

2019-10-21

2019-11-15

2023-02-03

2023-02-03

10元无门槛代金券