本文主要是介绍【LeetCode算法练习(C++)】4Sum,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:
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]
]
链接:4Sum
解法:同3Sum,三层循环嵌套一层指针移动,注意去除相同的集合。时间O(n^3)
class Solution {
public:vector<vector<
这篇关于【LeetCode算法练习(C++)】4Sum的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!