标签:
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.
解题思路:
首先肯定是一次排序,如果是暴力枚举的话,肯定超时。因此,我们可以采用分治的思想,存储所有2个元素的和,然后采用2SUM的思路求解即可,这样时间复杂度不过O(n^2)
JAVA实现如下:
标签:
原文地址:http://www.cnblogs.com/tonyluis/p/4471779.html