Question
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.
1 |
|
Analysis
这道题相当于是前面3 sum的一个升级,只是多了一个元素,解是思路上还是一个,多一个外层的循环,然后就可以把问题简化成3 sum
Solution
1 |
|
1 |
|