题目描述
英文题目
Given an array nums
of n integers and an integer target
, are there elements a, b, c, and d in nums
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.
Example:
1 | Given array nums = [1, 0, -1, 0, -2, 2], and target = 0. |
中文题目
给定一个包含 n 个整数的数组 nums
和一个目标值 target
,判断 nums
中是否存在四个元素 a,**b,c 和 d ,使得 a + b + c + d 的值与 target
相等?找出所有满足条件且不重复的四元组。
注意:
答案中不可以包含重复的四元组。
示例:
1 | 给定数组 nums = [1, 0, -1, 0, -2, 2],和 target = 0。 |
解决方法
方法一
- 描述
思路跟”三数之和“基本没啥区别,就是多加了一层for循环,其他的都一样
- 源码
1 |
|